donthedragon Posted January 13, 2011 Share Posted January 13, 2011 Hi. I want to implement a search on my website. I have various venues with certain specifics on the site. eg : how many people it can accommodate, its location, style etc. On my search, if someone puts in that they want the venue to accommodate 30 guests, How can I get it to search for all venues that can accommodate up to 30 guests, but no more. So all venues that can hold from 0 - 30 guests. Kind regards Donovan Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/ Share on other sites More sharing options...
BLaZuRE Posted January 13, 2011 Share Posted January 13, 2011 Use WHERE `your_field` < 30 Are you saying search as in text box or search as in searching your database with data provided from pre-made forms (drop-downs, checkboxes, etc)? Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1158996 Share on other sites More sharing options...
donthedragon Posted January 15, 2011 Author Share Posted January 15, 2011 Oh brilliant. I'll definitely give that a try. It is for a drop down in a search. Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1159716 Share on other sites More sharing options...
donthedragon Posted January 16, 2011 Author Share Posted January 16, 2011 It seems to be working. Thanks. I have some pagination that works with the search. I only want it to show if the user needs to view more than 10 at a time. If there is less than 10 I dont want the pagination to show at all. Please can you help rectify my code below : (I dont have a problem with this first code. I have just added it to show how it relates to the bottom code) <?php $area = $_POST['area']; $max_guests_to = str_replace(" ","",$_POST['max_guests_to']); $db = mysql_connect(localhost,'****','*****') or die("could not connect"); mysql_select_db('******') or die( "Unable to select database"); $query = "select * from property_profile where area='".mysql_real_escape_string($area)."' and max_guests < '".mysql_real_escape_string($max_guests_to)."'"; $numresults = mysql_query($query) or die("Query error: ". mysql_error()); $num_rows = mysql_num_rows($numresults); $page = 1; $prev_page = $page - 1; $next_page = $page +1; $num_pages = ceil($num_rows / 10) -1; $page_start = (10 * $page) - 10; $query = "select * from property_profile where area='".mysql_real_escape_string($area)."' and max_guests < '".mysql_real_escape_string($max_guests_to)."' LIMIT $page_start, 10"; $result = mysql_query($query) or die("Query error: ". mysql_error()); while($row = mysql_fetch_array($result)) { $reference = $row["reference"]; $venue_name = $row["venue_name"]; $area = $row["area"]; $max_guests = $row["max_guests"]; $description = $row["description"]; $list_image = $row["list_image"]; $star_grading = $row["star_grading"]; ?> Below is the pagination code : <?php // Set up the page links and pass any needed variables to the next page by including them in the href after the page variable. if (!$prev_page < "1") { print "<p style='clear:both;'><a href='results.php?page=$prev_page&num_pages=$num_pages'>< Previous page.</p>"; } if ($page != $num_pages) { print "<p style='clear:both;'><a href='results.php?page=$next_page&num_pages=$num_pages'> Next page.></p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1160170 Share on other sites More sharing options...
QuickOldCar Posted January 16, 2011 Share Posted January 16, 2011 I would think this should work. Give it a try. <?php // Set up the page links and pass any needed variables to the next page by including them in the href after the page variable. if (!$prev_page < 1) { print "<p style='clear:both;'><a href='results.php?page=$prev_page&num_pages=$num_pages'>< Previous page.</p>"; } if ($page >= 1 && $num_pages >= 2) { if ($page != $num_pages) { print "<p style='clear:both;'><a href='results.php?page=$next_page&num_pages=$num_pages'> Next page.></p>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1160190 Share on other sites More sharing options...
QuickOldCar Posted January 16, 2011 Share Posted January 16, 2011 Maybe you are happy with your code, but if wanted something more I wrote up a pagination script that controls the mysql start and stop rows. Also added +x amount of pages if available and a go to page text area as well. Here's the code in the forums http://www.phpfreaks.com/forums/php-coding-help/results-on-multiple-pages-help/msg1506457/#msg1506457 If want to test it, here's the live demo. http://get.blogdns.com/dynaindex/paginate.php Maybe can even use something from it for yours. Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1160202 Share on other sites More sharing options...
donthedragon Posted January 16, 2011 Author Share Posted January 16, 2011 Someone else did the code for me, so I would be more than happy to try something better. Thanks, Ill check it out and let you know. Quote Link to comment https://forums.phpfreaks.com/topic/224288-search-mysql-database/#findComment-1160351 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.