Jump to content

Help with outputs


gplevritis

Recommended Posts

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 tried
select * 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

[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

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.