Jump to content


PHP Pagination Code Error


2 replies to this topic

#1 bfva

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 22 March 2007 - 02:41 PM

I have created this code but it just keeps giving me an error. I am a noob at PHP and i know very little about debugging.

if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
switch($_GET['page']){
default:
break;
echo "Go to page: ";
$total_pages = "2";
for($i = 1; $i <= $total_pages; $i++){
break;
if(($page) == $i){
echo "$i "; 
case '1':
header('Location: index$i.php');
break;
} else {
echo "<a href=\"index.php?page=$i" title=\"Go to page $i\">$i</a> ";
case '$i':
header('Location: index$i.php');
break;
}
}
}

Thanks

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 22 March 2007 - 04:59 PM

Having some trouble understanding what you are trying to accomplish here. You can't just blatantly throw functions into a switch constructor, it expects cases to define what it is to execute. And sending the user to a new page... accomplishes what exactly?
Sorry, I'm having trouble with the logic of what you're doing, lol, it just makes no sense to me.

Here's a link to some basic pagination scripts, and I'll even PM you a pagination class I've made that should give you even more flexibility.

PHP: Page Numbering

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 March 2007 - 12:59 AM

You say you created that and it's giving you errors? Well, we can't get anywhere without knowing the errors, and neither can you. In fact, that script can't get anywhere. It looks as though you've thrown that code together by copying and pasting random code into a document and hoping it would work.

if(!isset($_GET['page'])){
	$page = 1;
} else {
	$page = $_GET['page'];
}

switch($_GET['page']){
	default:
	break;
	echo "Go to page: ";
	$total_pages = "2";
	for($i = 1; $i <= $total_pages; $i++){
		break;
		if(($page) == $i){
			echo "$i "; 
			case '1':
				header('Location: index$i.php');
			 break;
		} else {
			echo "<a href=\"index.php?page=$i" title=\"Go to page $i\">$i</a> ";
			case '$i':
				header('Location: index$i.php');
			break;
		}
	}
}
I'm not even going to bother begining to explain what is wrong with that code. There is so much i could easily write a new book on it.

Here is where you can go to figure out what you did.
http://php.net/manua...ures.switch.php
http://php.net/manua...ures.switch.php
http://php.net/manua...uctures.for.php
http://php.net/manual/en/language.control-...l-structures.if
http://php.net/manua...e.variables.php
http://php.net/manua...nction.echo.php

I'm sorry if i sound rude, but it looks as though you didn't even research what you were doing before you started, and that is one of my pet-peeves.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users