Jump to content

Querying from two tables


chrischen

Recommended Posts

This is my query

$query_new = sprintf("SELECT table1.text, table1.text2, table1.mid, table1.id, merch.id, merch.name, table1.expire FROM table1 INNER JOIN merch ON merch.mid = table1.mid WHERE table1.status = 'Y' AND table1.linkType = %s ORDER BY table1.$col $sort", GetSQLValueString("Text Link", "text"));

 

But when I echo $row_new['table1.id'] it outputs nothing however if I echo $row_new['id'] it gives me the value of merch.id.

 

I need to be able to echo table1.id and merch.id. How do I do this?

Link to comment
https://forums.phpfreaks.com/topic/91768-querying-from-two-tables/
Share on other sites

The safest bet to avoid overwriting stuff like this is to use "AS" statements, like...

 

SELECT table1.text, table1.text2, table1.mid, table1.id AS table1id, merch.id as merchid, merch.name, table1.expire FROM table1 INNER JOIN merch ON merch.mid = table1.mid WHERE table1.status = 'Y' AND table1.linkType = %s ORDER BY table1.$col $sort

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.