Greetings, I have a form where the user enters his search criteria and has the option to search in certain categories or to search all categories.
When the user searches in a specific category everything works great. However, when searching all the categories I get the initial page with the result, but when I click on the next link I just get a blank page. I've been stuck on this for a while and need a helping hand cause i'm exhausted from trying. Here's the html:
<head>
<title>Company</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form method="post" action="procsearch.php">
<table>
<td>
<input type="text" name="search_query">
</td>
<td>
<SELECT name="searchCategory" >
<OPTION VALUE="fullsearch">Search in all categories
<OPTION VALUE="lingoprogram">Lingo Programming
<OPTION VALUE="actionscript">Action Script Programming
<OPTION VALUE="director">Specific works in Macromedia Director
<OPTION VALUE="flash">Specific works in Macromedia Flash
<OPTION VALUE="3dmodelling">3D modelling
<OPTION VALUE="3danimation">3D animation
<OPTION VALUE="3Dgames">3D games
<OPTION VALUE="misc">Miscellaneous
</td>
</SELECT>
<td>
<input type="submit" name="Submit" value="Search">
</td>
</table>
</form>
</body>
And here's the php code:
<?
function pagenav() {
global $limit,$offset,$numpage,$where;
if ($where) {
$safewhere=urlencode($where);
}
echo "
<TABLE CELLPADDING=0 BORDER=0 CELLSPACING=5 WIDTH=100>
<TR>
<TD ALIGN=RIGHT>";
if ($offset>=$limit) {
$newoff=$offset-$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
<-- PREV</A>
</TD>";
} else {
echo "<-- PREV";
}
echo "<TD ALIGN=CENTER> ";
for ($i=1;$i<=$numpage;$i++) {
if ((($i-1)*$limit)==$offset) {
print "$i ";
} else {
$newoff=($i-1)*$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
$i</A> ";
}
}
echo " </TD>
<TD ALIGN=LEFT>";
if ($offset!=$limit*($numpage-1)) {
$newoff=$offset+$limit;
echo "<A HREF=\"$PHP_SELF?offset=$newoff&where=$safewhere\">
NEXT--></A>
</TD>";
}else{
echo "NEXT--></TD>";
}
echo "</TR>
</TABLE>";
} // END FUNCTION
// set this to the number of results you wish on each page
$limit=3;
// if no offset has been passed, offset should be 0
if (!$offset) $offset=0;
if (!$where) {
if (empty($search_query) || empty($searchCategory)) {
// some error handling as $one and/or
//$two not passed to initial page
echo "Please enter search";
}
$where="$search_query|$searchCategory";
}
$data=explode('|',$where);
if($searchCategory != 'fullsearch') {
$query_where="where description LIKE '%$data[0]%' AND category='$data[1]'";
} else {
$query_where="where description LIKE '%$data[0]%'";
}
// Connect to MySQL
$link = mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
// Select database
$db = mysql_select_db('database') or die(mysql_error());
$result=mysql_query("select count(*) from uploads $query_where");
list($numrec)=mysql_fetch_row($result);
#calc num pages
$numpage=intval($numrec/$limit);
if ($numrec%$limit) {
$numpage++; // add one page if remainder
}
$result=mysql_query ("select * from uploads $query_where limit $offset,$limit");
while($row = mysql_fetch_array($result))
{
//$count++;
// Loop through the $db->Records hash
while(list($key, $value) = each($row))
{
// Print only non-numeric indexes
//print(is_string($key) ? "<b>$key:</b> <font color = '956A6A'> $value</font><br>": "");
switch($key)
{
case "username" :
$key_replace = "Uploaded by";
print(is_string($key) ? "<b>$key_replace:</b> <font color = '956A6A'> $value
</font><br>": "");
break;
case "filename" :
$key_replace = "Filename";
print(is_string($key) ? "<b>$key_replace:</b> <font color = '956A6A'> $value
</font><br>": "");
break;
case "description" :
$key_replace = "Description";
print(is_string($key) ? "<b>$key_replace:</b> <font color = '956A6A'> $value
</font><br>": "");
break;
case "category" :
$key_replace = "Category";
print(is_string($key) ? "<b>$key_replace:</b> <font color = '956A6A'> $value
</font><br>": "");
break;
case "filepath" :
$key_replace = "";
print(is_string($key) ? "<b>$key_replace</b> <A HREF=$value>download this fi
le</A><br>": "");
break;
}
}
print("<p>");
}
if ($numpage>1) {
pagenav();
print "<P>";
}
?>