WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-11-2004, 06:56 PM
WebProWorld New Member
 

Join Date: Oct 2004
Posts: 2
sdreams RepRank 0
Default php and mysql search

hello,

my website is mainly regarding vacation rentals of all kind in Spain. All accommodations are added manually and then shown in their respective province ordered alphabetically by town.

I would like to offer a search function to the visitors and hope it is ok to show a link to a page (see information in the center) I prepared in order to explain what I would like to set up:

http://www.spaindreams.com/eng/search.htm


I know that somehow this search could be done with php and mysql.
My web runs on Linux and PHP and Mysql are installed.

Help on this would be very much appreciated as I have been looking quite a lot for information, but....

Thanks for reading my message
Reply With Quote
  #2 (permalink)  
Old 10-13-2004, 06:02 PM
WebProWorld New Member
 

Join Date: Aug 2004
Posts: 13
pipeten RepRank 0
Default

I'm not sure exactly how your tables are setup but the PHP && SQL below should give you some general idea ;)


Code:
if(!empty($_POST['type'])) {
 $where[] = "type='".mysql_escape_string($_POST['type'])."'";
}
if(!empty($_POST['region'])) {
 $elements[] = "region='".mysql_escape_string($_POST['type'])."'";
}
if(!empty($_POST['location'])) {
 $elements[] = "location='".mysql_escape_string($_POST['type'])."'";
}
WHERE
if(count($elements) >= 1) {
  foreach($elements as $key => $value) {
    $where .= $elements[$key]." && ";
  }
  $query = "SELECT data FROM property WHERE ".substr($where,0,-4).";";
}
hope that makes atleast a little sense ;)
__________________
web hosting reviews
Reply With Quote
  #3 (permalink)  
Old 10-13-2004, 06:06 PM
WebProWorld Pro
 

Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

Without knowing your table structures... An over-simplified way to do this would be
1. use simple names and values in your 'SELECT's
2. pass any the relevant variables to a query
3. run the query against your database.
4. have a "results page" display titles that link to the appropriate record.

e.g. SELECT *
FROM TblProperties
WHERE type='$TipoAlojamiento'
AND pool='$pool'
AND ac='$AC'
etc.. etc...

You can get more sophisticated by dynamically creating the query based on the variables, and using other operators like OR.

I hope this helps.

Steve
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #4 (permalink)  
Old 10-13-2004, 06:09 PM
WebProWorld New Member
 

Join Date: Aug 2004
Posts: 13
pipeten RepRank 0
Default

Code:
if(!empty($_POST['type'])) { 
 $where[] = "type='".mysql_escape_string($_POST['type'])."'"; 
} 
if(!empty($_POST['region'])) { 
 $elements[] = "region='".mysql_escape_string($_POST['type'])."'"; 
} 
if(!empty($_POST['location'])) { 
 $elements[] = "location='".mysql_escape_string($_POST['type'])."'"; 
} 
if(count($elements) >= 1) { 
  foreach($elements as $key => $value) { 
    $where .= $elements[$key]." && "; 
  } 
  $query = "SELECT data FROM property WHERE ".substr($where,0,-4).";"; 
}
removed the random 'WHERE' ;) you could make this more lean by putting the if statements into a function i.e.

Code:
function where_build($fieldname) {
  if(!empty($_POST[$fieldname])) {
    $returnData = $fieldname."='".mysql_escape_string($_POST[$fieldname])."'";
  }
return $returnData;
}
unset($elements);
$elements[] = where_build('type');
$elements[] = where_build('location');
$elements[] = where_build('region');

if(count($elements) >= 1) {
  foreach($elements as $key => $value) {
    $where .= $elements[$key]." && ";
  }
  $query = "SELECT data FROM property WHERE ".substr($where,0,-4).";";
}
You could take it even further from their and allow where_build to take its data as an array but i'll shut up now :D
__________________
web hosting reviews
Reply With Quote
  #5 (permalink)  
Old 10-14-2004, 06:12 PM
WebProWorld New Member
 

Join Date: Oct 2004
Posts: 2
sdreams RepRank 0
Default search query

thanks a lot for your information.

as i am new to all this i might look for somebody to set this up.
i havenīt created a mysql database nor anything else so far.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0