Jump to content

Query Which Use Previou Query Please


justlukeyou

Recommended Posts

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

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;
. ");

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.