954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

MySql Search using multiple input.

Hi i had a mysql database ( coading in php ) in my real estate web site. It had 4 columns.

1. for ( ie, buy or rent )
2. district
3. Type ( villa,house,.....)
5. price ( 1 lakh, 2lakh, 3 lakh ...)

I need to add a searh in my home page. Using any of the colomns in above. I already did it with

all these columns like

("select * from database where for='$for' and district='$district' and type='$type' and price='price'").

Now I need to do custom search like district= All , type=All and price=Any.....

Please help me.....
Thanks in Advance
Rajeesh

rajeesh_rsn
Posting Whiz in Training
265 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

select * from database
would work just fine since you want all the records without satisfying any condition :)
Btw, 'for' and 'type' are mysql reserve keywords and requires ` to be wrapped around it.
like, `for`, `type`.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

@naveen : Good point there about the keywords, but I guess he has framed his question wrong.

@OP : Would you be able to define a custom search in more detail or reframe your question, cause "district = all, typ = all and price = all" is not a search at all.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

Ok. I meant that it is not mandatory to select all the inputs. for example
User can search for "rent" by keeping district "all" type "all" and price "any"...
another one . User can search for "rent" and district "abc" and type"all" and also price "any"

One more search for "rent" by keeping district "all" type "all" and price "2lakh"...

please help me...
thanks for supports...

rajeesh_rsn
Posting Whiz in Training
265 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

If the user has selected "All" or "any", exclude it from your query condition list. :-/
For example, If he search for "rent" and keeps district as "all" and price as "2 lakh", your query should look something like,

select * from table where `for`='rent' and price='2 lakhs'

I still don't understand how is this advance search. :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

For a custom search, what you can do is, have multiple queries written each for a different search that can be done on your database and select the appropiate one to fire, dynamically, based on the search parameters entered by your user.

verruckt24
Posting Shark
952 posts since Nov 2008
Reputation Points: 485
Solved Threads: 89
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You