Jump to content

Recommended Posts

I joined two tables.  However, both tbles have a fieldname called "pod".  How do I echo out that field name so it is from the correct table?

 

$consultsq1 = "SELECT * FROM icu INNER JOIN bundle ON icu.id_incr = bundle.pt_id  "; 
$result = mysql_query ($consultsq1) or die ("Invalid query: " . mysql_error ());
for($n=0;$row = mysql_fetch_assoc ($result);$n++) {
echo $row['pod'];
}

 

When I echo pod, it gives me it from the icu table but not the bundle table.  Thanks!

$consultsq1 = "SELECT *,thecorrecttable.pod FROM icu INNER JOIN bundle ON icu.id_incr = bundle.pt_id  ";
$result = mysql_query ($consultsq1) or die ("Invalid query: " . mysql_error ());
for($n=0;$row = mysql_fetch_assoc ($result);$n++) {
   echo $row['pod'];
}

When joining tables like that you are best to specify what fields you want..

If you want all from 1 table and 2 fields from the second do this.

table1.*, table2.field1, table2.field2

Then you know you are getting the result you want.

 

taquitosensei: that will still select all the fields from all the tables that have been joined.

But I need to query pod from table 1 and pod from table 2, so I need to select BOTH of them (even though they are named the same).  When echoing, how do I echo the correct pod.  Lets say i want to compare the value of pod in table 1 with the value of pod in table 2 (which is what i want to do)?

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.