I'm using a pretty std Paging class . It's works 100% if the SQL statement I pass to the Class is in this form:
$que = "SELECT * FROM data Where catagory=1";
but if I have a form pass a variable to this page called $catagory, then I use the SQL statement
$que = "SELECT * FROM data Where catagory=$catagory";
I can only read the first page of results from my table. It shows the correct number of pages. (i.e. 1 - 2 - 3 - 4 - 5 ...) But when I try to goto the enxt page or any other page it's blank.
below is the code I'm trying to use to do this without success. The page before this that passes the variable $catagory is a simple form that has a <select> with the name catagory.
<?php
require('pagedresults.php');
echo "<td class=body align=center width=100%>";
$host= "localhost";
$user = "******";
$pass = "*";
$db = "******";
$cid = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db, $cid) or die(mysql_error());
$que = "SELECT * FROM movies Where catagory=$catagory";
$rs = new MySQLPagedResultSet($que, 5, $cid);
echo "<table border=0 cellpadding=3 cellspacing=2 class=movies>";
while ($row = $rs->fetchArray()){
echo "<tr><td width=140><b>$row[1]</td><td>";
if ($row[10] < "0"){
echo "Sorry all copies are currently rented</td></tr>";
}
else{ echo "</td></tr>";}
echo "<tr><td><img src=$row[11] height=160 width =100 border=0 alt=$row[1]></td>";
echo "<td><blockquote>$row[2]</blockquote></td></tr>";
echo "<tr height=5><td colspan=2></td></tr>";
}
echo "</table>";
echo "<p>";
echo $rs->getPageNav("aid=$aid");
echo "<tr><td class=footer align=center>Home - Sign in - Join - DVD's - FAQ - Site map</td></tr>";
echo "</table>";
?>
AND HERE IS THE CLASS I'M using. I've used it succesffuly before but not using a variable in my SQL statement
<?php
class MySQLPagedResultSet
{
var $results;
var $pageSize;
var $page;
var $row;
function MySQLPagedResultSet($query,$pageSize,$cnx)
{
global $resultpage;
$this->results = @mysql_query($query,$cnx);
$this->pageSize = $pageSize;
if ((int)$resultpage <= 0) $resultpage = 1;
if ($resultpage > $this->getNumPages())
$resultpage = $this->getNumPages();
$this->setPageNum($resultpage);
}
function getNumPages()
{
if (!$this->results) return FALSE;
return ceil(mysql_num_rows($this->results) /
(float)$this->pageSize);
}
function setPageNum($pageNum)
{
if ($pageNum > $this->getNumPages() or
$pageNum <= 0) return FALSE;
$this->page = $pageNum;
$this->row = 0;
mysql_data_seek($this->results,($pageNum-1) * $this->pageSize);
}
function getPageNum()
{
return $this->page;
}
function isLastPage()
{
return ($this->page >= $this->getNumPages());
}
function isFirstPage()
{
return ($this->page <= 1);
}
function fetchArray()
{
if (!$this->results) return FALSE;
if ($this->row >= $this->pageSize) return FALSE;
$this->row++;
return mysql_fetch_array($this->results);
}
function getPageNav($queryvars = '')
{
if (!$this->isFirstPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()-1).'&'.$queryvars.'">Prev</a> ';
}
if ($this->getNumPages() > 1)
for ($i=1; $i<=$this->getNumPages(); $i++)
{
if ($i==$this->page)
$nav .= "$i ";
else
$nav .= "<a href=\"?resultpage={$i}&".
$queryvars."\">{$i}</a> ";
}
if (!$this->isLastPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()+1).'&'.$queryvars.'">Next</a> ';
}
return $nav;
}
}
?>
Any help at all, Thanks