Jump to content

Recommended Posts

I need to perform a search of my DB using 6 fields. I want to progress thru the searches as so:

 

Row: A B C D E F

 

Select A, if A then select B, if B then select C if C then select D, if D select E, if E then select F

 

I then want to extract the data from each field.

 

if A then $a = A, if B then $b = B, etc etc.

 

I don't want to have a whole bunch of different select statements or if conditions if I don't need to. Also, the DB is rather large so i think evaluating:

 

$query = "SELECT * FROM table"

 

Might be overkill. Is there anyway to do something like:

 

$queryA = SELECT * FROM table WHERE A = subject1
if($queryA){$queryB = SELECT * FROM $queryA WHERE B = subject2}
if($queryB){$queryC = SELECT * FROM $queryB WHERE C = subject3}
etc etc etc

 

So basically I just progressively filter down one original mysql query to get what I need.

Link to comment
https://forums.phpfreaks.com/topic/210888-progressive-databse-searching/
Share on other sites

Maybe I am not understanding the request - kind of confusing. But, it seems he is just wanting a query with multiple where clauses:

SELECT *
FROM table
WHERE A = subject1
  AND B = subject2
  AND C = subject3
  AND D = subject4
  AND E = subject5
  AND F = subject6

Hmm, on re-reading the original post, this might be a job for left joins .. eg

 

SELECT A,B,C,D,E,F FROM tab1
LEFT JOIN tab2 ON (tab2.A = tab1.A)
LEFT JOIN tab3 ON (tab3.B = tab2.B)
...
WHERE A = subject1

 

That implements "If there's a result from tab1, then fetch matching data from tab2.  If there's a result from tab2, fetch matching data from tab3"

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.