Thank you for the javascript tip. I will look into the merits of using that method.
I have provided the script that I have so far.
I can get the first page to return the selected number of results, with links to the next page. but when I hit the link to the next page this is the error message I see.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/masterte/public_html/thelittens/pagination.html on line 58
Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%%' LIMIT 0, 3
HERE IS MY SCRIPT
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Welcome to Adobe GoLive 6</title>
</head>
<body bgcolor="#ffffff">
<?
include("files/picturedata.inc");
//getting data from search page
$find= $GET["find"]; //search terms
$p_find=$find;
$in= $GET["in"]; //keyword
$logic= $GET["logic"]; // boolean OR or AND
$sort= $GET["sort"]; //how to sort results
$limit= $GET["fill"]; //number of pics per page
$size= $GET["size"]; //thumbnail size
$find = trim($find); //clean up the search terms
$page=$_GET["page"]; //gets the page that we are on
$findarray = explode(" ",$find);
@mysql_connect($hostname, $username, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db($dbName) or die("ERROR--CAN'T CONNECT TO DB");
if(empty($page)){
$page = 1;
if(!$findarray){$findarray='%';}
else { //else 1
$query_count = "SELECT * FROM $usertable WHERE $in LIKE '%$findarray[0]%' ";
if ($logic == 'or') {
For ($i=1; $i<count($findarray); $i++) {
$query_count .= "OR $in LIKE '%$findarray[$i]%' ";
} //end for
} //end if
else {
For ($i=1; $i<count($findarray); $i++) {
$query_count .= "AND $in LIKE '%$findarray[$i]%' ";
} //end for
} //end else
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
} //end else
}
$limitvalue = $page * $limit - ($limit);
// insert Query here
if(!$findarray){$findarray='%';}
else {
$query = "SELECT * FROM $usertable WHERE $in LIKE '%$findarray[0]%' ";
if ($logic == 'or') {
For ($i=1; $i<count($findarray); $i++) {
$query .= "OR $in LIKE '%$findarray[$i]%' ";
} //end for
} //end if
else {
For ($i=1; $i<count($findarray); $i++) {
$query .= "AND $in LIKE '%$findarray[$i]%' ";
} //end for
} //end else
} // end
$query .= "LIMIT $limitvalue, $limit";
//end of inserted query
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
echo("<table width='100%' border ='0' cellspacing ='5' cellpadding='5' align='center'>");
$x=0; //for page format
while($row = mysql_fetch_array($result)){
if ($x ==3) {
print ("<tr>");
$x=0;
}
print ("<td>");
print ("<div align = 'center'>");
print ("<a href='singlephoto.html?photoid=$row[0]'><img width='188' src='../photopages/photos/$row[0].jpg'></a>");
print ("<br>");
print ("$row[1]"); print ("<br>");
print ("<img width ='66' src='images/spacer.gif'>");
print ("</div>");
print ("<td>");
$x++;
}
echo("</table>");
if($page != 1){
$pageprev = $page-1;
// $pageprev = $pageprev --;
echo("<a href=\"$PHP_SELF?fill=$limit?find=$p_find?page=$pageprev\">PREV".$limit."</a> ");
}else{
echo("PREV ".$limit." ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?fill=$limit?find=$p_find?page=$i\">$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?fill=$limit?find=$p_find?page=$i\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page+1;
echo("<a href=\"$PHP_SELF?fill=$limit?find=$p_find?page=$pagenext\">NEXT".$limit."</a>");
}else{
echo("NEXT".$limit);
}
mysql_free_result($result);
?>
</body>