cgraz, awsome code! i was looking for a solution to this exact problem and your code did it BUT now I am at a deadend as I have tried to implement this in a search page that has PREVIOUS and NEXT but have not been able to fix this.
Here is my complete code. I hope that someone could guide me in the right direction.
<?php
session_start();
session_register();
include 'config/db_connect.php';
include("config/config.php");
include("templates/top.htm");
include("templates/left.htm");
$submit='';
$year = date("Y");
if ($birth_year) {
$birth_year = ($year - $birth_year);
} else {
$birth_year='';
}
$to = $to;
if($to == "") { $to = "%%"; }
if($state == "NONE") { $state = "%%"; }
//if($to == "") { $to = "%%"; }
$age_min = "$age_min";
$age_max = "$age_max";
$pagelimit = "3";
$now = getdate();
$nmonth = $now['month'];
$nday = $now['mday'];
$nyear = $now['year'];
$sql = "SELECT * FROM clients"; // change to your table name
foreach($_POST as $key => $value) {
if($sql == "SELECT * FROM clients") { // change to your table name
$sql .= " WHERE $key like '%$value%'";
} else {
$sql .= " AND $key like '%$value%'";
}
}
print $sql . "<br>"; // useful for error checking until it's working properly
$query = mysql_query("$sql") or die(mysql_error());
$totalrows = mysql_num_rows($query);
$pagenums = ceil ($totalrows/$pagelimit);
// determine how many pages there will be by using ceil() and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if ($page==''){ $page='1'; }
// create a start value
$start = ($page-1) * $pagelimit;
// blank matches found
echo "
<body bgcolor=\"#CBD3FA\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
<table width=\"100%\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\" bgcolor=\"#CBD3FA\">
<tr bgcolor=\"#CBD3FA\">
<td width=\"74%\" valign=\"top\">\n";
// Showing Results 1 to 1 (or if you're page limit were 5) 1 to 5, etc.
$starting_no = $start + 1;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
// create dynamic next, previous, and page links
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$sql = "SELECT * FROM clients"; // change to your table name
foreach($_POST as $key => $value) {
if($sql == "SELECT * FROM clients") { // change to your table name
$sql .= " WHERE $key like '%$value%'";
} else {
$sql .= " AND $key like '%$value%'";
}
}
//$result = mysql_query("$sql LIMIT $start,$pagelimit") or die(mysql_error());
//REMOVE THIS
if (mysql_num_rows($result) > 0) {
echo "
<table width=\"100%\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\" bgcolor=\"#CBD3FA\">
<tr>
<td colspan=\"2\" height=\"9\" valign=\"top\">
<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" bordercolor=\"#000066\" bgcolor=\"#ECEEFF\">
<tr>
<td width=\"23%\">
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">
";
// previous link
if ($page>1) {
echo "<a href='fsearch.php?state=$state&to=$to&".($page-1)."' class=searchlinks>Previous</a>";
} else {
echo "Previous";
}
echo "
</font></div>
</td>
<td width=\"54%\">
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">Goto
Page ";
// dynamic page number links
for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='fsearch.php?state=$state&to=$to&page=$i'>$i</a>";
}
else {
echo " <b>$i</b>";
}
}
echo "</font></div>
</td>
<td width=\"23%\">
<div align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">
";
if ($page<$pagenums) {
echo "<a href='fsearch.php?state=$state&to=" . $to . "&page=".($page+1)."'>Next Page</a>";
} else {
echo "Next Page";
}
echo "</font></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=\"2\" height=\"103\">
";
$sql = "SELECT * FROM clients"; // change to your table name
foreach($_POST as $key => $value) {
if($sql == "SELECT * FROM clients") { // change to your table name
$sql .= " WHERE $key like '%$value%'";
} else {
$sql .= " AND $key like '%$value%'";
}
}
$sql .= " LIMIT $start,$pagelimit";
$result = mysql_query("$sql") or die(mysql_error());
$totalrows = mysql_num_rows($result);
while ($r = mysql_fetch_array($result)) {
$ethnic = $r['ethnic'];
$bodyType = $r['bodyType'];
$m = $r['birth_month'];
$d = $r['birth_day'];
$y = $r['birth_year'];
$feet = $r['feet'];
$inches = $r['inches'];
$cm = $r['cm'];
$state = $r['state'];
$state = $r['state'];
switch ($ethnic) {
case '1': $ethnic = "caucasian (white)"; break;
case '2': $ethnic = "african american (black)"; break;
case '3': $ethnic = "asian"; break;
case '4': $ethnic = "hispanic"; break;
case '5': $ethnic = "first nations"; break;
case '6': $ethnic = "east indian"; break;
case '7': $ethnic = "middle eastern"; break;
case '8': $ethnic = "other"; break;
}
switch ($bodyType) {
case 'a': $bodyType = "Slim"; break;
case 'b': $bodyType = "Fit"; break;
case 'c': $bodyType = "Muscular"; break;
case 'd': $bodyType = "Average"; break;
case 'e': $bodyType = "Few extra pounds"; break;
case 'f': $bodyType = "Prefer not to say"; break;
}
$query= mysql_query("SELECT states_name FROM states WHERE states_value=$state") or die (mysql_error());
while($row = mysql_fetch_array($query)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
} }
$now = getdate();
$nmonth = $now['month'];
$nday = $now['mday'];
$nyear = $now['year'];
if ($nmonth < $m OR $nmonth = $m AND $nday < $d) {
$userage = $nyear - $y - 1;
} else {
$userage = $nyear - $y;
}
$client_id = $r["client_id"];
$thumb = "/client_images/nopicture.jpg";
$query= mysql_query("SELECT * FROM client_images where client_id='$client_id'") or die (mysql_error());
while($row = mysql_fetch_array($query)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
}
$sizzle = "SELECT average FROM imagetable WHERE client_id = $client_id";
$sizzle = mysql_query($sizzle);
$sizzle = mysql_fetch_array($sizzle);
echo "
<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" bordercolor=\"#000066\" bgcolor=\"#ECEEFF\">
<tr>
<td>
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td width=\"26%\" valign=\"top\" height=\"112\">
<div align=\"center\">
<p> </p>
<p><a href=/profile.php?id=$client_id><img src=$thumb></a>
<br>
</p>
</div>
<p align=\"center\"><b><font color=\"#CC0000\">sizzle or fizzle </font><font color=\"#FF3300\">" . $sizzle[average] . "</font></b></p>
<div align=\"center\"></div>
</td>
<td width=\"74%\" height=\"112\">
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" bordercolor=\"#000066\">
<tr valign=\"top\">
<td colspan=\"2\">
<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\" bordercolor=\"#000066\" bgcolor=\"#FFFFFF\">
<tr>
<td>
<p>" . $r['nickname'] . " " . $r['client_id'] . "</p>
<p>" . $r['openingLine'] . "</p>
</td>
</tr>
</table>
<br>
<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\" bordercolor=\"#000066\" bgcolor=\"#FFFFFF\">
<tr>
<td colspan=\"1\" width=\"49%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\"><b><font color=\"#000066\">
$userage
</font></b><font face=\"Verdana, Arial, Helvetica, sans-serif\">years
old</font></font></td>
<td colspan=\"4\" width=\"51%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">
";
if(!$r['cm']) {
echo "$feet Feet, $inches Inches";
} else {
echo "$cm cm";
}
echo "</font></td>
</tr>
<tr>
<td colspan=\"1\" width=\"49%\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Ethnicity is <font color=\"#000066\"><b>$ethnic</b></font></font></td>
<td colspan=\"4\" width=\"51%\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\"><b><font color=\"#000066\">$bodyType</font></b> body</font></td>
</tr>
<tr>
<td colspan=\"1\" width=\"49%\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Located
in <font color=\"#000066\"><b>" . $r['city'] . ", $states_name</b></font>
</font></td>
<td colspan=\"4\" width=\"51%\">
<font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Last Online </font></td>
</tr>
</table>
</td></tr></table>
</td></tr></table>
</td></tr></table>
<BR>
";
}
} else {
echo "No data.";
}
echo "
</td>
</tr>
</table>
</td>
";
include("templates/right.php");
include("templates/bottom.htm");
mysql_free_result($result);
?>