Jump to content

Progressive databse searching


xcandiottix

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"

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.