I get an invalid argument when trying to create this output of pages to
limit to 20 records per pages.  I removed the line and it stopped the error,
but the next and previous buttons will go on and on even if there is no more
records so I am thinking it is my mysql_num_rows() function

I have gotten this script from here:


If you know of a better one or can help me out on this one, that is much

Actual error is:

not a valid mySQL result resource

here is the code:


   $numresults = mysql_query("SELECT * FROM booklist");
  $numrows = mysql_num_rows($numresults);
             < ---------------------------------------- FAILS HERE
// next determine if offset has been passed to script, if not use 0
print "Pages:";
if (empty($offset)) {
$connection = @mysql_connect("localhost", "", "") or die ("could not connect
to database");
$db = @mysql_select_db("db", $connection) or die("Could not select
$sql = "SELECT id,title, author, subject FROM booklist LIMIT $offset,
$limit = 20;

// get results
$result = mysql_query($sql, $connection) or die("Could not execute query");
while ($row = mysql_fetch_array ($result))

// next we need to do the links to other results

if ($offset==1) { // bypass PREV link if offset is 0
    print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> &nbsp; \n";

// calculate number of pages needing links

// $pages now contains int of pages needed unless there is a remainder from
if ($numrows%$limit) {
    // has remainder so add one page

for ($i=1;$i<=$pages;$i++) { // loop thru
    print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> &nbsp; \n";

// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
    // not last page so give NEXT link
    print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";


PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to