Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old May 17th, 2009, 10:11 AM   #1
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Searching a mysql database

Hi
Im trying to search my database. I have 3 things to search : areas, general info and price range.
When I search just the area and price range, all works. When I search area and general info, all works. But I cant seem to get all three to work together.

The columns in my DB involved in my search are :areas, pool, security, storey & price.

Below is my search query
$query = "select * from sothebys where areas='$area' and (pool like '%".$general."%' or security like '%".$general."%' or storey like '%".$general."%') and (price between '$price_from' and '$price_to')";

Can anyone see off-hand what I am doing wrong?

Cheers
Donovan

Last edited by donovan; May 17th, 2009 at 10:19 AM..
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 19th, 2009, 08:52 AM   #2
Reputable Member
 

Join Date: Nov 2008
Location: Lexington, KY
Posts: 243
Thanks: 0
Thanked 1 Time in 1 Post
Rep Altering Power: 0 Dubbs is on a distinguished road
Re: Searching a mysql database

First, I am going to assume you are using PHP. If so remember to include mysql_real_escape_string around your variables in the query. If any of these variables have a sigle or double quote in them, your query may be causing an error.

Code:
$query "select * from sothebys where areas='".mysql_real_escape_string($area)."' and (pool like '%".mysql_real_escape_string($general)."%' or security like '%".mysql_real_escape_string($general)."%' or storey like '%".mysql_real_escape_string($general)."%') and (price between '".mysql_real_escape_string($price_from)."' and '".mysql_real_escape_string($price_to."')" or die(mysql_error()); 
Again, assuming you are using PHP, for testing purposes add or die(mysql_errror()) at the end of your query will allow you to determine if your query has errors in it. Be sure to remove this before you move the script into production, since it can be used to compromise your site.
Dubbs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 19th, 2009, 09:15 AM   #3
WebForumz Member
 

Join Date: Mar 2008
Location: South Africa
Posts: 58
Thanks: 2
Thanked 1 Time in 1 Post
Rep Altering Power: 0 donovan is on a distinguished road
Re: Searching a mysql database

Thanks for getting back to me.
What a bonus! Looks like it works fine.
I used to be able to give a thanks on here, how do I do that now.

Thanks alot
Donovan
donovan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with INT in mysql database donovan Databases 3 April 30th, 2009 12:50 PM
Can't get a third table in MySQL database to work twmprys Databases 2 October 21st, 2008 10:09 AM
[SOLVED]Searching a database CloudedVision PHP 6 July 1st, 2008 11:42 AM
mysql database ezagents Databases 4 June 2nd, 2006 02:32 PM
excel -> mysql database riotman Databases 3 January 30th, 2006 06:59 PM


Search Engine Optimization by vBSEO 3.2.0 RC8