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? Link to comment https://forums.phpfreaks.com/topic/228705-query-which-use-previou-query-please/ 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; . "); Link to comment https://forums.phpfreaks.com/topic/228705-query-which-use-previou-query-please/#findComment-1179118 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. Link to comment https://forums.phpfreaks.com/topic/228705-query-which-use-previou-query-please/#findComment-1179154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.