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

 

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.