justlukeyou Posted February 24, 2011 Share Posted February 24, 2011 I am trying to create a query which reads and uses a previous query which could go on for upto four queries. For example: Query: $carcolour(red), Query: $carmodel(ford), Query: $enginesize(1600), Query: $carlocation(New York) This displays all red cars, which are Ford, which 1600CC, which are located in New York. or Query: $enginesize(1600), Query: $carcolour(red), Query: $carmodel(ford), Query: $carlocation(New York) This displays all 1600CC cars, which red car, which are Ford, which are located in New York. (Same result as above) I have found this guide but Im not sure it what I am looking for. I have also come across the Join function. However this seems to be based on joining two seperate queries. http://www.suite101.com/content/how-tor-run-multiple-mysql-queries-with-php-a105672 Can anyone advise on the best way to create a set of queries which reads and uses the results of the previous query? Quote Link to comment Share on other sites More sharing options...
samoht Posted February 24, 2011 Share Posted February 24, 2011 is this all coming from the same db table? are all the values in separate fields? if so you only needs one query - in your php code you can insert as much criteria as you like : ("SELECT * FROM yourTable WHERE 1 . if(isset($carcolor)) ' AND carcolor = '. $carcolor; if(isset($carmodel)) ' AND carmodel = '. $carmodel; . "); Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted February 24, 2011 Author Share Posted February 24, 2011 Great thanks, yes its all coming from the same db in different fields. So do they read off each other so a link: .php?carcolor=red&carmodel=ford and .php?carmodel=ford&carcolor=red Will both return Red Ford cars. Its seems by far the simpliest method I have seen of doing this. Quote Link to comment 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.