Jump to content


Photo

Easy Pagination?


  • Please log in to reply
6 replies to this topic

#1 Nightseer

Nightseer
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 September 2006 - 01:45 PM

Is there an easy way to do pagination? I have now tried every tutorial I can find and still getting some of the most aggravating errors............and of course, it just didn't work. Anyway, the code below is the function that needs it-if you can help, or point in correct direction, it would be GREATLY appreciated ???

<?
function market($breed, $gender)
{

$loop = mysql_query("SELECT * FROM dogs WHERE sellprice > 0 ORDER BY sellprice") or die ('cannot select dogs for sale');
$count = mysql_num_rows($loop);
	$i = 1;
	$cols = 2;
while ($row = mysql_fetch_array($loop))
{
$dogid = $row['dogid'];
$name = getName($dogid);
$breed = getBreed($row['breed']);
$age = getAge($dogid);
$price = getSalePrice($row['sellprice']);
		if($i == 1){
			echo "<tr>";
		}
echo "
		<td align=\"left\" valign=\"top\" width=\"50%\"><br><a href=dog.php?dogid=$dogid>$name</a>, $breed $age $price" . "</td>";
		if($i == $cols){
			echo "</tr>";
			$i = 1;
		}
		else{
			$i++;
		}
}
	}//end while
?>


#2 speedy33417

speedy33417
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 30 September 2006 - 01:51 PM

You can't just echo <a href=dog.php?dogid=$dogid>
Part of it is html and other part is php. Like $dogid has no value in html

Switching back and forth between html and php goes something like this:

echo "<a href=dog.php?dogid=" . $dogid . "more html code";

Hope this helps.

Also here's a nice tutorial for paging
http://www.phpnoise.com/tutorials/9/1



#3 Nightseer

Nightseer
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 September 2006 - 01:52 PM

Um-that code seems to be working fine?
Was needing a way to make it list on more than one page.....

#4 speedy33417

speedy33417
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 30 September 2006 - 02:13 PM

Not to mention that you're missing a " sign around your href.

<a href"=dog.php?dogid=something">

Also you said:

Um-that code seems to be working fine?

Are you asking or saying?

#5 Nightseer

Nightseer
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 30 September 2006 - 02:20 PM

No-it lists the dogs correctly-lol-though that solved another list problem I was working on. I'm not sure WHY that one lists correctly-but it does....

#6 intrik

intrik
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 30 September 2006 - 03:17 PM

You can't just echo <a href=dog.php?dogid=$dogid>


Yeah you can, I do it all the time.
<?php
echo"<a href='page.php?a=$var'>";
?>


#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 01 October 2006 - 01:09 PM

You can't just echo <a href=dog.php?dogid=$dogid>


Yeah you can, I do it all the time.
<?php
echo"<a href='page.php?a=$var'>";
?>


Speedy,

To explain a little further, and hopefully be a little more helpful than the previous post...  When using double quoted strings " " the variable is read and the value of it is output.  This is not true of single quoted strings ' '.  So:

<?php
$name = "HuggieBear";

echo "My name is $name"; // Prints My name is HuggieBear

echo 'My name is $name'; // Prints My name is $name
?>

I hope this helps.
Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users