Hi,
Can anyone help me. I'm trying to display 20 results per page. It finds the amount of records and displaye the correct navigation bar but no results show up.
Also get this message:
Warning: Supplied argument is not a valid MySQL result resource in /xxx/xxxx/x.php on line 59
Any ideas.
This is my code im using
<?php
$limit=20; // rows to return
$numresults=mysql_query("select * from TABLE where YOUR CONDITIONAL HERE order by WHATEVER");
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=1;
}
// get results
$result=mysql_query("select id,name,phone ".
"from TABLE where YOUR CONDITIONAL HERE ".
"order by WHATEVER limit $offset,$limit");
// now you can display the results returned
while ($row = mysql_fetch_array($result))
{
($result); //LINE 59
echo "<td>".stripslashes($row["company"])."</td>";
echo "<td>".stripslashes($row["contact"])."</td>";
echo "<td>".stripslashes($row["cid"])."</td>";
echo "<td>".stripslashes($row["telno"])."</td>";
}
// next we need to do the links to other results
if ($offset==1) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link $newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a>
\n";
}
?>