Jump to content

Easy Pagination?


Nightseer

Recommended Posts

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 ???

[code]<?
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
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/22591-easy-pagination/
Share on other sites

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:

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

Hope this helps.

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

Link to comment
https://forums.phpfreaks.com/topic/22591-easy-pagination/#findComment-101363
Share on other sites

[quote author=intrik link=topic=110073.msg444247#msg444247 date=1159629440]
[quote author=speedy33417 link=topic=110073.msg444219#msg444219 date=1159624279]
You can't just echo <a href=dog.php?dogid=$dogid>
[/quote]

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

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:

[code]<?php
$name = "HuggieBear";

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

echo 'My name is $name'; // Prints My name is $name
?>
[/code]

I hope this helps.
Regards
Huggie
Link to comment
https://forums.phpfreaks.com/topic/22591-easy-pagination/#findComment-101797
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.