开发者

How to manage query?

$query_message23 = "select * from messages_system as m, members as me where m.mes_id='$messageId' AN开发者_StackOverflow社区D 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


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 !


You have a condition:

   ...AND m.frm_id=me.mem_id

no wander they are the same.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜