Help needed with paging code not working
Posted: Wed Aug 16, 2006 12:59 am
Everah | Please use
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Can someone please help me with my code. It is supposed to be a search engine that takes 3 parameters (Name, Category,State). It should print 10 records to a page, and the remainder records should be sent to the next page. However, it is not working and I dont know whats wrong with the code. I've been on it for 3 days. Please can someone help?Code: Select all
<?php
require_once('./mysql_connect.php'); //connect to the db.
$var = @$_GET['business_name'];
$var2 = @$_GET['category'];
$var3 = @$_GET['state'];
//$limit=10;
// Handle the form.
/* Create an empty new variable.
if (isset($var)) {
$business_name = TRUE;
}
// Check for a category.
if (isset($var2)) {
$category = TRUE;
}
if (isset($var3)) {
$state = TRUE;
}
if (!isset($var) && !isset($var2) && !isset($var3))
{
echo "<p>We dont seem to have a search parameter!</p>";
}
*/
$query = "SELECT * FROM Users WHERE "; // start of string
$sub = NULL; //initialize substring
if (isset($_GET['business_name']) && strlen($_GET['business_name']) > 0)
{
$sub = "Business_Name LIKE '%" . $_GET['business_name'] . "%'";
}
if (isset($_GET['category']) && strlen($_GET['category']) > 0)
{
$sub .= is_null($sub) ? " Category = '" . $_GET['category'] . "'" : " AND Category = '" . $_GET['category'] . "'";
}
if (isset($_GET['state']) && strlen($_GET['state']) > 0)
{
$sub .= is_null($sub) ? " State ='" . $_GET['state'] . "'" : " AND State ='" . $_GET['state'] . "'";
}
$limit = 10;
$s = empty($s) ? 0 : $s;
$query .= $sub . "ORDER BY Business_Name, City LIMIT $s, $limit"; // end of string
$numresults = @mysql_query($query);
$numrows=mysql_num_rows($numresults);
$result = mysql_query($query) or die("Couldn't execute query");
echo "<p>You searched for:"" .$var . ", ". $var2 . ", ". $var3 . ""</p>";
echo "Results <br />";
$count = 1 + $s;
while ($row=mysql_fetch_array($result)){
$title=$row["Business_Name"];
echo "$count $title <br />";
$count++;
}
$currPage = (($s/$limit)+1);
echo "<br />";
if ($s >= 1){
$prevs = ($s-$limit);
print " <a href="$PHP_SELF?s=$prevs&business_name={$_GET['business_name']}&category=${$_GET['category']}&state={$_GET['state']}"><< Prev 10 </a> ";
}
$pages=intval($numrows/$limit);
if($numrows % $limit){
$pages++;
}
if(!((($s + $limit)/$limit)== $pages) && $pages != 1){
$news = $s + $limit;
echo " <a href = "$PHP_SELF?s=$news&business_name={$_GET['business_name']}&category={$_GET['category']}&state={$_GET['state']}">Next 10 >></a>";
}
$a = $s + ($limit);
if ($a > $numrows)
{
$a = $numrows;
}
$b = $s + 1;
echo "<p>Showing results $b to $a of $numrows</p>";
?>Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[color=red][b]Everah[/b] | I modified your post title to be a little more in line with what you actually need help with.[/color]
[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
, we should at least help figure out his original issue. 