Paging listed results
Hello;
i wrote a php code that list all the products in my database table, and i want to divide the results (every 3 products listed in a page), the table contains 5 fields (prodname, specs, price, picname, id (Auto Increment)). The code below is not working fine on phpdev, there is no error, just logic error.
when i use it to display results, for example i have 5 products in my table. it displays 3 products in the first page (prod5,prod4,prod3) , and page 2, it displays them again. not (prod2, prod1).
i think the problem is in $row = mysql_fetch_array($result);
i thought of using if statement but didnt manage to get it!
what confuses me, that i uploaded the code in my website, and it worked fine!!! so i need help to make it work on my website and phpdev please
<?php
if ($step == NULL)
{
$step=0;
$step2=$step+3;
}else{
$step2=$step+3;
}
$count=0;
$query1 = \"SELECT * FROM prod ORDER BY id DESC\";
$result1 = mysql_query($query1);
while ($row = mysql_fetch_array($result1))
{
$count++;
}
$query = \"SELECT * FROM prod ORDER BY id DESC LIMIT \".addslashes(\"$step\").\",4\";
$result = mysql_query($query);
if ($count == 0)
{
echo\"No results found\";
}
if ($count < 4)
{
$min = 1;
}else{
$min = 0;
}
$ccc=0;
for ($c = 1; $c <= 3; $c++)
{
$ccc++;
$row = mysql_fetch_array($result);
$prodname= $row[\"prodname\"];
$price= $row[\"price\"];
$specs= $row[\"specs\"];
$picname= $row[\"picname\"];
if ($picname == NULL)
break;
echo \"$ccc- $prodname, $specs, $price, $picname<BR>\";
}
echo \"<center>\";
for ($l=0;$l<=$count;$l=$l+3)
{
if ($l == $step)
{
echo \"[\".($l/3+1).\"]\";
echo \" \";
}else{
echo \"<a href=\\"blabla.php?step=$l\\">[\".($l/3+1).\"]</a>\";
echo \" \";
}
}
?>
Abhishek Reddy posted this at 13:48 — 4th September 2004.
He has: 3,348 posts
Joined: Jul 2001
Is the database (including contents) on phpdev identical to the one on your web site?
You can check if $row differs by printing $row somewhere to debug. If the value of $row matches on both servers, then you know it's a problem with the logic in the processing of data.
Sorry I'm not much help now. I'll try take a closer look later.
And welcome to TWF!
djnaf posted this at 17:05 — 4th September 2004.
They have: 2 posts
Joined: Sep 2004
ya the same database
but i think this code cause noise!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.