Hi everyone!
I am desperate to find an answer to this problem. I have read through (and tried to use) anout 6 different tutorials, but I just cannot fix this. It would mean so much to me if someone could tell me what I am doing wrong, my brain is really starting to hurt over this!!
I have a search (for realestate), that results in all the properties for the search criteria to show up (eg state, price etc etc). I wanted to limit the number of properties per page to 3, and to have links saying, "next 1, 2, 3, 4" etc etc. Now I know it has something to do with limits, but I can't get it to work.
If I put $limit = $maxRows_p it says:
'showing results 1 - 3 of 3'. But there are actually 16 results available. When I Take out the $limit I get:
the correct 'showing 1 - 3 of 16' but all the results are on the first page. (doesn't limit it to 3).
And the:
$from = (($pageNum_p * $maxRows_p) - $maxRows_p);
$sql = 'SELECT * FROM items LIMIT $from, $maxRows_p';
Doesn't seem to do anything (works the same if I take it out).
Please help! I have been trying to do this for 12+ hours. Thanks Michelle.
Code:
#### BUILD SEARCH SQL BASED ON SEARCH TYPE ####
#defauts
$maxRows_p = 3;
if(!isset($_GET)){
$pageNum_p = 1;
} else {
$pageNum_p = $_GET;
}
$startRow_p = (($pageNum_p * $maxRows_p) - $maxRows_p);
$from = (($pageNum_p * $maxRows_p) - $maxRows_p);
$sql = 'SELECT * FROM items LIMIT $from, $maxRows_p';
## Start building sql for GET varables for advanced search
//Add min square feet
if(isset($_REQUEST) && ($_REQUEST != ''))
$search[] = ' sqft >= '.$_REQUEST;
//Add Garage
if(isset($_REQUEST) && ($_REQUEST != ''))
$search[] = ' garage = "'.$_REQUEST.'"';
//Add lot size
if(isset($_REQUEST) && ($_REQUEST != ''))
$search[] = ' lot_size >= '.$_REQUEST;
//implode to search string on ' and ';
$searchStr = @implode(' and ',$search);
$sql = 'select * FROM items WHERE (expires > NOW()) and active = "Yes" and ';
$sql .= $searchStr;
### DEBUG
if($debugP) echo 'Advanced Search Sql<hr>'.$sql;
$error = 'No results found, please search again';
### Finished Building search sql and execting #####
$sql .= $sort;
//Perform search
$searchResults = $mysql->exSql($sql);
### BUILD OUTPUT ####
if (isset($_GET)) {
$totalRows_p = $_GET;
} else {
$all_p = mysql_query($sql);
$totalRows_p = @mysql_num_rows($all_p);
}
$totalPages_p = ceil($totalRows_p/$maxRows_p)-1;
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $totalPages_p; $i++){
if(($pageNum_p) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER."?pageNum_p=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $totalPages_p){
$next = ($pageNum_p + 1);
echo "<a href=\"".$_SERVER."?pageNum_p=$next\".>Next>></a>";
}
echo "</center>";
?>
THANK-YOU,
Michelle.