Hi to all,
I'm displaying a set of records in different pages.
The user will be able to search by category, let say a user wants to search
projects that belong to 'PHP' category, so I will list all the projects that
belong to that category.
My problem is: the first 10 records on the first page display without any
problem, but when I try to go to the next page it doesn't display any
record.
The weird thing is that if I write my query: SELECT * FROM 150BK WHERE
CATEGORY='PHP', I don't any problem I can see all my record and go through
from page to page. But when I write my query requesting the name from the
drop down menu from the search page I get just the first 10 records.
For example, SELECT * FROM 150BK WHERE CATEGORY='$category' //here is where
the problem

Any help is greatly appreciate
Thanks in advanced
Nato

here is my code
<?
include "./connection.php";
?>
<html>
<head>
<title>Record Set Paging with Page Navigation</title>
</head>
<body>
<font face='verdana, arial' size=3><b>
PHP/MySQL Record Set Paging with Page Navigation</b><font size=2><br>
<?
global $limit, $sql, $url, $pagesize, $pagecount, $absolutepage,
$recordcount;

$sql = ("SELECT * from 150bk wehere category='$category'");
   $result = mysql_query($sql);
   $record_count = mysql_num_rows($result);


$pagesize = 10 ;
$url = $PHP_SELF ;
if (!isset($absolutepage)) {    // Set offset and absolutepage if not set
        $absolutepage = 1;
    $offset = 0;
}  else {
   $offset = ( $absolutepage - 1 ) * $pagesize  ;
}
if (!isset($total_rows)) {    // Get total_rows at startup
   $result = mysql_query($sql);
   $recordcount = ( mysql_num_rows($result) ) -1;
   $pagecount = intval($recordcount / $pagesize);
   if ($recordcount % $pagesize ) $pagecount++;
}
if ($recordcount > 0) {
   $sql .= " LIMIT $offset, $pagesize ";   // Get record set = pagesize
every time
   $result = mysql_query($sql);
   if ($absolutepage == 1) {
        $pag1 = $absolutepage;
   } else {
        $pag1 = (($absolutepage - 1) * $pagesize) + 1;
   }
   $pag2 = $pag1 + ($pagesize - 1);
   if ($pag2 > $recordcount)
        $pag2 = $recordcount;
   echo "<hr><font face='verdana, arial' size=2>";
   echo "Displaying records $pag1 to $pag2 (of " . $recordcount.")<hr>";
   PagNav($pagesize, $pagecount, $absolutepage, $recordcount, $sql, $url) ;
   echo "<hr>";
   $fields = mysql_num_fields($result);
     for ($i=0; $i < $pagesize; $i++) {
     while($query_data = mysql_fetch_array($result))
     {
     $id = $query_data[ID];
     $name = $query_data[NAME];
      echo $id. " | ".$name. " " . "<a href='resPNav2.php?test=$id'>read
more..." . "</a>" . "<br>";
      echo "<hr>";
      }
       echo "<br>\n";
   }

   } else {
   echo "No records found.";
}
echo "</body></html>";


function PagNav($pagesize, $pagecount, $absolutepage, $recordcount, $sql,
$url)
{
global $sql, $url, $pagesize, $pagecount, $absolutepage, $recordcount;
$pad="" ;
$maxpages = $pagecount ;
if ( ($absolutepage % 10) == 0) {
   $counterstart =  $absolutepage - 9 ;
} else {
   $counterstart = $absolutepage - ($absolutepage % 10) + 1 ;
}
$counterend = $counterstart + 9 ;
echo "<font size=1><b>Page ".$absolutepage." of ".$pagecount.": </b>";
if ($counterend > $maxpages) $counterend = $maxpages ;
if ($counterstart != 1) {
   $ref = "<a href='" . $url ;
   $ref .= "?absolutepage=" . "1" ;
   $ref .= "'>First</a>&nbsp;|&nbsp;" ;
   echo $ref ;
   $ref = "<a href='" . $url ;
   $ref .= "?absolutepage=" . ($counterstart - 1) ;
   $ref .= "'>Prev 10 Pages</a>&nbsp;" ;
   echo $ref ;
}
echo "<b>[ </b>" ;
for ($counter = $counterstart; $counter < $counterend +1;$counter++ ) {
    if ($counter >= 10) $pad="" ;
    if (! ($counter == $absolutepage)) {
       $ref = "<a href='" . $url ;
       $ref .= "?absolutepage=" . $counter ;
       $ref .= "'>" . $pad . $counter . "</a>" ;
    } else {
       $ref = "<b>" . $pad . $counter . "</b>" ;
    }
    echo $ref ;
    if (!($counter == $counterend)) print " " ;
}
echo "<b> ]</b>" ;
if ($counterend != $maxpages) {
    $ref = "&nbsp;<a href='" . $url ;
    $ref .= "?absolutepage=" . ($counterend + 1) ;
    $ref .= "'>Next 10 Pages</a>" ;
    echo $ref ;
    $ref = "&nbsp;|&nbsp;<a href='" . $url ;
    $ref .= "?absolutepage=" . $maxpages ;
    $ref .= "'>Last</a>" ;
    echo $ref ;
}
echo "</font>";
}
?>


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

Reply via email to