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
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

Link to comment
Share on other sites

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.