Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/224288-search-mysql-database/
Share on other sites

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>";
				}
			 ?>

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>";
               }
               }
             ?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.