user439555
user439555

Reputation: 95

How to manage query?

$query_message23 = "select * from messages_system as m, members as me where m.mes_id='$messageId' AND m.frm_id=me.mem_id";

it gives output

Array ( [mes_id] => 826 [mem_id] => 334 [frm_id] => 334 [subject] => Re: Re: Re: Re: Re: Hola! [body] => i dno i just made it up lollllllllllllllllllll

Artin wrote:

Haha.. Dooskie??? Is that Russian? lol

aurita wrote:

PFFFFFFT!!!!!!!!!!!
YOU KNOW HOW I DOOSKIE! LMAO!

you can see that mem_id and frm_id are the same. How? I am confused. When i run this query in phpmyadmin i get mem_id 48 and frm_id 334 from messages_system and from members table (as i joined 2 tables) mem_id 334, so i think this members mem_id is overriding on messages_system mem_id.

Please suggest.

Thanks

Upvotes: 1

Views: 67

Answers (4)

gmadd
gmadd

Reputation: 1156

Try only selecting the fields you want,

SELECT m.mes_id, me.mem_id, m.frm_id, m.subject, m.body FROM ...

Use m.mem_id AS m_mem_id to avoid overwriting fields with the same name.

Upvotes: 1

Scherbius.com
Scherbius.com

Reputation: 3414

You have a condition:

   ...AND m.frm_id=me.mem_id

no wander they are the same.

Upvotes: 1

Marc B
Marc B

Reputation: 360702

If you're joining tables and there's two or more duplicate field names in those joined tables, you should use an alias to distinguish them

SELECT table1.mem_id AS mem_id1, table2.mem_id AS mem_id2
FROM ...

which gives you mem_id1 and mem_id2 in your fetched array.

Upvotes: 0

krtek
krtek

Reputation: 26597

I really doubt you get different mem_id and frm_id in phpmyadmin since this is in your where clause :

 m.frm_id=me.mem_id

I know nothing about your table structure, but it's obvious to me that frm_id and mem_id must be the same in order for the query to return something !

Upvotes: 2

Related Questions