this is a searching function
the max result is 30, if more than 30, it has "- Prev 1 2 Next -"
it shows the correct result, but if i press next, it shows these errors:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 61
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 90
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\phpweb\searching.php on line 133
<?PHP
// $reqlevel sets the accesslevel a user needs to hace
// use 0 (zero) if you want to make it an admin only page.
// and 1 (one) is default for an new user.
// this makes the page an member only page.
include("config.php");
$search = $HTTP_GET_VARS["search"];
$searchname = $HTTP_POST_VARS["searchname"];
$name = $HTTP_POST_VARS["name"];
$gender = $HTTP_POST_VARS["gender"];
$state = $HTTP_POST_VARS["state"];
$lowage = $HTTP_POST_VARS["lowage"];
$highage = $HTTP_POST_VARS["highage"];
$image = $HTTP_POST_VARS["image"];
$page = $HTTP_POST_VARS["page"];
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK href="help.css" rel=stylesheet type=text/css>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<?
$currentyear=$currentyear=strftime("%Y");
?>
</td>
</tr>
<tr>
<td>
<?php
mysql_select_db($database, $conn);
if(!$conn)
{
echo "Couldn't make a connection!!!";
exit;
}
$db = mysql_select_db($database,$conn);
if(!$db)
{
echo "The database disapeared!";
mysql_close($conn);
exit;
}
$image="";
if(isset($_POST['image']) && $_POST['image'] == 1) {
$image .= ' AND image = 1 ';
}
$max = 0;
$bmax = mysql_query("SELECT * from ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and '$currentyear'-dobyear >= $lowage and '$currentyear'-dobyear <= '$highage' {$image}");
while ($row = mysql_fetch_array($bmax))
{
$max++;
}
?>
<font size="2">
<?php
$image="";
if(isset($_POST['image']) && $_POST['image'] == 1) {
$image .= ' AND image = 1 ';
}
echo"<table border=0 cellspacing=0 width=80% align=center>";
echo "</td><td height=\"12\" align=\"right\" bgcolor=\"lightcyan\" width=\"100%\"><font size=2>";
echo "<center>Database record returned<font color = blue> $max </font>
items.</center>";
echo "</td></tr></form></table><br>";
$maxresult = 30;
$sql_text = ("SELECT * from ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and '$currentyear'-dobyear >= $lowage and '$currentyear'-dobyear <= '$highage' {$image}");
if (!$page) {
$page = 1;
}
$backpage = $page - 1;
$nextpage = $page + 1;
$query = mysql_query($sql_text);
$start = ($maxresult * $page) - $maxresult;
$num_rows = mysql_num_rows($query);
if ($num_rows <= $maxresult) {
$num_pages = 1;
} else if (($num_rows % $maxresult) == 0) {
$num_pages = ($num_rows / $maxresult);
} else {
$num_pages = ($num_rows / $maxresult) + 1;
}
$num_pages = (int) $num_pages;
if (($page > $num_pages) || ($page < 0)) {
error("You have specified an invalid page number");
}
$sql_text = $sql_text . " LIMIT $start, $maxresult";
$query = mysql_query($sql_text);
if ($max>$maxresult)
{
echo "<center>- ";
if ($backpage) {
echo "<a href=\"searching.php?search=$search&page=$backpage\">Prev</a>";
} else {
echo "Prev";
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo " <a href=\"searching.php?search=$search&page=$i\">$i</a> ";
} else {
echo " $i ";
}
}
if ($page != $num_pages) {
echo "<a href=\"searching.php?search=$search&page=$nextpage\">Next</a> -";
} else {
echo "Next -";
}
echo "</center>";
}
?><CENTER>
<table CELLSPACING="2" CELLPADDING="2" BORDER="0" width="70%">
<font size=2>
<?php
$a = $start + 1;
print " <TR bgcolor=slateblue><TD font size=2 align=center height=\"26\"><font font size=2 color=white><b>Nickname</TD><TD align=center><font size=2 color=white><b>Gender</TD><TD align=center><font size=2 color=white><b>Age</TD><TD align=center><font size=2 color=white><b>Location</TD><TD align=center><font size=2 color=white><b>Country</TD><TD align=center><font size=2 color=white><b>Headline</TD></TR>\n";
while ($row = mysql_fetch_array($query)) {
?>
<?php
$image="";
if(isset($_POST['image']) && $_POST['image'] == 1) {
$image .= ' AND image = 1 ';
}
$res = mysql_query("SELECT * FROM ".$DBprefix."signup WHERE username like '%$searchname%' and fullname like'%$name%' and state like'%$state%' and gender like'$gender%' and userlevel='1' and actnum='0' and '$currentyear'-dobyear >= $lowage and '$currentyear'-dobyear <= '$highage' {$image}");
if(mysql_num_rows($res) > 0) {
echo"<tr>";
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
echo '<td bgcolor="'.$color.'"><font size=2> <b><a class=hq href="viewuser.php?name='.$row['username'].'" target="_blank">'.$row['username'].'</a>';
if($row['image'] == 1) {
echo ' <img src="members/image/camera.gif" alt="camera" />';
}
echo '</td>'."\n";
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
"$row[gender]\n";
$currentyear=strftime("%Y");
$currentdate=strftime("%d-%m-%Y");
$age = $currentyear - $row[dobyear];
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
echo'<td align=center bgcolor="'.$color.'">';
"$row[gender]\n";
if($row['gender'] == 'male') {
echo '<img src="members/image/'.substr($row['gender'], 0, 1).'.jpg" alt="'.$row['gender'].'" />';
}
else {
echo '<img src="members/image/'.substr($row['gender'], 0, 1).'.jpg" alt="'.$row['gender'].'" />';
}
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
echo'<td align=center bgcolor="'.$color.'">';
echo"<font size=2>$age";
"$row[gender]\n";
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
echo'<td align=center bgcolor="'.$color.'">';
echo"<font size=2>$row[location]";
"$row[gender]\n";
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
echo'<td align=center bgcolor="'.$color.'">';
echo"<font size=2>$row[country]";
"$row[gender]\n";
$pic1 = strtolower(substr($row['gender'], 0, 1));
$color1 = ($pic1 == 'm') ? 'blue' : 'red';
echo'<font color="'.$color1.'">';
$pic = strtolower(substr($row['gender'], 0, 1));
$color = ($pic == 'm') ? 'aliceblue' : '#fff0ff';
$color1 = ($pic1 == 'm') ? 'blue' : 'red';
echo'<td bgcolor="'.$color.'"><font color="'.$color1.'">';
echo"<font size=2>$row[headline]";
"$row[gender]\n";
$a++;
}
else {
echo 'No users found';
}
?>
</body>
</html>
<?php
}
echo "</table>";
if ($max>$maxresult)
{
echo "<br><center>- ";
if ($backpage) {
echo "<a href=\"searching.php?search=$search&page=$backpage\">Prev</a>";
} else {
echo "Prev";
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo " <a href=\"searching.php?search=$search&page=$i\">$i</a> ";
} else {
echo " $i ";
}
}
if ($page != $num_pages) {
echo "<a href=\"searching.php?search=$search&page=$nextpage\">Next</a> -";
} else {
echo "Next -";
}
echo "</center>";
}
?></font>