Dave Carrera wrote: > Hi List, > > How do I select data from 24 table in my database. > > Each one is identical in structure layout being > > Id,name,list > > I want to select where like $_POST[var] from a form all of the tables > but I am having trouble :( > > I thought making a var string like > > $string = "table1,table2,table3,....."; > > And doing > > (select * from $string where list like \"%$_POST[var]%\"); > > Would work but I get a MySql error which say "Column: 'list' in where > clause is ambiguous" > > I am stumped so I ask the list for help or advise please. > > Any advise is very much appreciated and I thank you in advance for > any help or pointers. > > Thank you > > Dave C
Try constructing a query that looks like this... select 't1' as source, t1.* from t1 where t1.list like "$criteria" union select 't2' as source, t2.* from t2 where t2.list like "$criteria" union select 't3' as source, t3.* from t3 where t3.list like "$criteria" union ... select 't24' as source, t24.* from t24 where t24.list like "$criteria" ; This query can be created by 1. storing all the table names in an array 2. constructing the individual select portion using array_map() 3. combining all individual selects using join($selects, 'union') -- Richard A. DeVenezia -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php