darknessmdk Posted June 14, 2007 Share Posted June 14, 2007 Hi all, Having a problem with my pagination code. if($both == "0"){ $query_count = "SELECT * FROM properties WHERE (city = '$city' OR state = '$state' OR zip = '$zip')AND price BETWEEN '0' AND '$price'"; } elseif($price == "0") { $query_count = "SELECT * FROM properties WHERE (city = '$city' OR state = '$state' OR zip = '$zip')AND beds = '$beds' AND baths = '$baths'"; } elseif($beds == "0") { $query_count = "SELECT * FROM properties WHERE (city = '$city' OR state = '$state' OR zip = '$zip')AND baths = '$baths' AND price BETWEEN '0' AND '$price'"; } elseif($baths == "0") { $query_count = "SELECT * FROM properties WHERE (city = '$city' OR state = '$state' OR zip = '$zip')AND beds = '$beds' AND price BETWEEN '0' AND '$price'"; }else{ $query_count = "SELECT * FROM properties WHERE city = '$city' AND beds = '$beds' AND baths = '$baths' AND price BETWEEN '0' AND '$price' OR state = '$state' AND beds = '$beds' AND baths = '$baths' AND price BETWEEN '0' AND '$price' OR zip = '$zip' AND beds = '$beds' AND baths = '$baths' AND price BETWEEN '0' AND '$price'"; } $limit = 2; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $pages = ceil($totalrows / $limit); $limitvalue = $page * $limit - ($limit); $query_order = " ORDER BY date DESC LIMIT $limitvalue, $limit"; $query = $query_count."".$query_order ; echo $query_count; $result = mysql_query($query) or die("Error: " . mysql_error()); It lists the first page of results fine, when you click on next or a page number it shows no results. This started happening after I added the if else statements. I have it printing out my sql statment and I noticed that its cutting off half of the statement. Ive never had anything like this happen before. Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/ Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 Where does it cuts off? Perhaps add an space after the ')' and before 'AND' FD Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274793 Share on other sites More sharing options...
darknessmdk Posted June 14, 2007 Author Share Posted June 14, 2007 I tried adding the space, it doesnt have an effect the sql statement is out puts in the second page is this SELECT * FROM properties WHERE (city = '' OR state = '' OR zip = '') AND price BETWEEN '0' AND '' Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274805 Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 Are you sure $price has a value? Echo it to check that...perhaps you have an error located above this part of the script. FD Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274807 Share on other sites More sharing options...
chocopi Posted June 14, 2007 Share Posted June 14, 2007 how could a price be between 0 and '' Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274813 Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 Yeah, thats the problem. $price is probably '', so the query will return BETWEEN '0' AND '' as an error. Thats why I ask him to test if $price has a value. FD Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274817 Share on other sites More sharing options...
darknessmdk Posted June 14, 2007 Author Share Posted June 14, 2007 price has a value on the first page, as does everything else. On the second page it doesnt Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274821 Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 Ah, I see. I guess it uses the query of the first page on the second page, instead of the query of the second page. Is $both == '0' true on the second page? FD Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274831 Share on other sites More sharing options...
darknessmdk Posted June 14, 2007 Author Share Posted June 14, 2007 No it comes up blank, Any suggestion on how to fix this? How can I pass the variables along to the next page with out reposting them in a form? Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274837 Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 Set a session with the page name and make a if else statement for the session . $_SESSION['page'] = '1'; is page one $_SESSION['page'] = '2'; is page two etc etc You get it? Perhaps visit php.net for more information on sessions. Never use hidden form objects, but use sessions instead. FD Quote Link to comment https://forums.phpfreaks.com/topic/55610-pagination-issues/#findComment-274839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.