Jump to content

Archived

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

Nightseer

Easy Pagination?

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
Not to mention that you're missing a " sign around your href.

[code]<a href"=dog.php?dogid=something">[/code]

Also you said:

Um-that code seems to be working fine?

Are you asking or saying?

Share this post


Link to post
Share on other sites
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....

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.