Hello, I am still fairly new and trying desperately to learn, but I'm stumped on a problem. I am using php and mysql to make an interactive dating website. For my search results I am using a NEXT] 1 - 2 - 3 [PREV script to sort and break the results down into seperate pages. I am limiting the results to ten results per page. I believe my problem is somewhere within the "select" statement. If I leave the select statement like this everything works fine.
$getrows = mysql_query("select * from $dbtable");
$numrows=mysql_num_rows($getrows);
$query = mysql_query("select * from $dbtable limit $offset,$limit");
while ($result=mysql_fetch_array($query)){
All my results come up and all the links for the NEXT] 1 - 2 - 3 [PREV work fine.
But if I change the select statement to something like this,
$getrows = mysql_query("select * from $dbtable WHERE state = 'state' and age = 'age'" );
$numrows=mysql_num_rows($getrows);
$query = mysql_query("select * from $dbtable WHERE state = 'state' and age = 'age' limit $offset,$limit");
while ($result=mysql_fetch_array($query)){
I get one page with my first ten results which is what I want. All the links NEXT] 1 - 2 - 3 [PREV are at the bottom of the page. The problem is when I press the NEXT link or one or the 1-2-3 links, I get a blank page and zero results. I know that there are more than just the ten results that are showing on the first page. But everytime I click one of the links for the next page of results I get zero results on my next page.
I have tried four different scripts and I have the same problem with everyone of them.I am leaving a copy of the full script I am using in particular right now at the bottom of this page. If anyone can please tell me where I am going wrong it would be greatly appreciated.
Thankyou,
Steve
<?
echo "<style type=\"text/css\">
body, td {font-family:tahoma; font-size:13; color:black;}
a {font-family:tahoma; font-size:13; color:black;}
a:Visited {font-family:tahoma; font-size:13; color:black;}
a:Hover {font-family:tahoma; font-size:13; color:black;}
a:active {font-family:tahoma; font-size:13; color:black;}
</style>";
$server = "";
$userid = "";
$pass = "";
$database = "";
$dbtable = "";
$limit = 10;
$con = mysql_connect("$server","$userid","$pass") or die ("Can't Connect to Server");
$db = mysql_select_db("$database",$con) or die("Can't Connect to Database");
if (empty($offset) || $offset < 0) {
$offset=0;
}
if (empty($index)) $index=0; / This is to count the line index of the results /
$getrows = mysql_query("select * from $dbtable WHERE category = 'Beanie Bears'", $con);
$numrows=mysql_num_rows($getrows);
$query = mysql_query("select * from $dbtable WHERE category = 'Beanie Bears' limit $offset,$limit", $con);
while ($result=mysql_fetch_array($query)){
$index++; /* Increment the line index by 1 */
// Your results layout goes here
}
if ($numrows <= $limit) {
/ Added this statement so if the result shows less that or the
equal ammount of the limit to show nothing at all , to kill
the "1" that was just generated /
}
else {
// Don't display PREV link if on first page
if ($offset!=0) {
$prevoffset=$offset-$limit;
echo "[Previous]   ";
}
else echo "[Previous]   ";
// Calculate total number of pages in result
$pages = intval($numrows/$limit);
// $pages now contains total number of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// Now loop through the pages to create numbered links
// ex. 1 2 3 4 5 NEXT
for ($i=1;$i<=$pages;$i++) {
// Check if on current page
if (($offset/$limit) == ($i-1)) {
// $i is equal to current page, so don't display a link
echo " $i ";
} else {
// $i is NOT the current page, so display a link to page $i
$newoffset=$limit*($i-1);
echo " $i \n";
}
}
// Check to see if current page is last page
if (!((($offset/$limit)+1)==$pages) && $pages!=1) {
// Not on the last page yet, so display a NEXT Link
$newoffset=$offset+$limit;
echo "    [Next]
\n";
}
else echo "   [Next]";
}
mysql_close($con);
?>[/color]