Jump to content

Need Help with PHP Query


o0Loco0o

Recommended Posts

I have 3 tables, and what I am trying to do is get this to output

just the characters.name and appropriate guild.name for that character.

 

Table: characters

Columns: guid, name

 

Table: guild_member

Columns: guid, guildid

 

Table: guild

Columns: guildid, name

 

I have tried this query:

SELECT characters.name, guild.name
FROM characters, guild
WHERE guild_member.guid = characters.guid AND guild_member.guildid = guild.guildid

 

But it did not work... =(

 

Please Help!

 

Thank you in advance!

Link to comment
https://forums.phpfreaks.com/topic/268492-need-help-with-php-query/
Share on other sites

Use explicit JOINs instead of the implicit ones you've used above. The explicit ones gives you more control, and considerably lessens the risk of getting a Cartesian product. Not to mention that they make it a whole lot easier to read what's actually going on. ;)

 

That said you do have a problem with your logic here, as you're only joining two of the three tables. Also, since this appears to be a many-to-many relation you might want to read up on how them. There are plenty of good guides online, so just search about until you find one. Mind the crappy ones though. :P

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.