Hey
im having a little trouble creating a script to display so many results per page from my query. it displays the number of results in my case 2 but when i click next it says cannot execute query can any one provide any suggestiions im running out of ideas, any help would be most appreciated. my code is below
<?php
$conn = @mysql_connect("some_host", "some_user", "some_pwd")
or die("Sorry unable to connect to MySQL");
$rs = @mysql_select_db( "", $conn ) or die ( "Sorry unable to select specified database" );
$category = $POST['category'];
$criteria = $POST['criteria'];
// how many rows to show per page
$rowsPerPage = 2;
// by default we show first page
$pageNum = 1;
// if $GET['page'] defined, use it as page number
if(isset($GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT * FROM customer_table WHERE $category LIKE '%$criteria%' LIMIT $offset, $rowsPerPage";
$result = mysql_query( $query, $conn ) or die ( "Sorry unable to execute query" );
while($row = @mysql_fetch_array($result))
{
echo "<table><tr>
<td width='30' height='30' align='center'><input name='id' type='radio' value='$row[customer_id]'></td>
<td width='438' height='30'><font face='arial' size='2'> $row[first_name] $row[surname]</font></td>
</tr></table>";
}
// how many rows we have in database
$query = "SELECT COUNT(*) AS numrows FROM customer_table";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;