Jump to content

echo a variable after a JOIN


jeff5656

Recommended Posts

if I join two tables and one of the fieldnames is the same in both tables, how do I echo out the correct one?

as an example,

$query = "SELECT * FROM food, more_food ";
$results = mysql_query ($query) or die (mysql_error());
while ($row = mysql_fetch_assoc ($results)) {

 

Now the following "made sense", but it doesn't work.  How do i speciy the variable from the correct table if the ieldnames are the same in both tables?

echo "the type of apple is $row['food.apple'];

Link to comment
https://forums.phpfreaks.com/topic/202415-echo-a-variable-after-a-join/
Share on other sites

No, unless it is more than 100 fields, writing out the query once shouldn't be that big of a deal :)

 

Also, have you examined your results of that query? I believe that will create a result row for every row in the right table appended to every row of the left table...

 

so, if table 1 has 3 rows, and table 2 has 5 rows, your result set is going to be 15 records. That does not sound like a desirable result, but I could be wrong :)

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.