gplevritis Posted January 6, 2007 Share Posted January 6, 2007 I have a two tables.Table 1: has two records (id,name): (001, bob) and (002,Tim)Table 2: has one record (id1,id2): (001, 002)How do I built my select statement to ouput Tim and Bob from the record in Table 2. I thought I could use:select * from table1, table2 where table2.id1=table1.id and table2.id2=table1.id; This outputs nothing.I also triedselect * from table1, table2 where table2.id1=table1.id OR table2.id2=table1.id; but the output of id1 is the same as id2.Any thoughts? Link to comment https://forums.phpfreaks.com/topic/33099-help-with-outputs/ Share on other sites More sharing options...
jwk811 Posted January 6, 2007 Share Posted January 6, 2007 [code]$sql = "SELECT id1, id2 FROM table2";$result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ extract($row);$sql = "SELECT name FROM table1 WHERE id = $id1 OR id = $id2";$result = dbQuery($sql); while($row = mysql_fetch_assoc($result)) { extract($row);}}echo $name;[/code]that should work.. im pretty sure theres an easier way to do it but try that if you want to Link to comment https://forums.phpfreaks.com/topic/33099-help-with-outputs/#findComment-154219 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.