Jump to content

Fun with Joins/Headaches


ifm1989

Recommended Posts

To dumb this down as much as possible, I have the following tables:

 

wars, wars_participants, users, alliance_members, alliance

 

I want to be able to search active wars.

 

So the query would have to collect data in the following fashion:

 

War #1

- - - - wars_participants (on war_id) -> alliance_members (on participant_user_id) -> alliance (on alliance_id) -> users (on participant_user_id)

- - - - wars_participants (on war_id) -> alliance_members (on participant_user_id) -> alliance (on alliance_id) -> users (on participant_user_id)

 

War #2

- - - - wars_participants (on war_id) -> alliance_members (on participant_user_id) -> alliance (on alliance_id) -> users (on participant_user_id)

- - - - wars_participants (on war_id) -> alliance_members (on participant_user_id) -> alliance (on alliance_id) -> users (on participant_user_id)

 

etc.etc.

 

 

I'm able to get this far, but it only collects data for ONE participant. I need it to collect for all of them, so it can be searchable by alliance name and user name.

$sql = "SELECT * FROM ".$prefix."wars
	LEFT JOIN `".$prefix."wars_participants` ON ".$prefix."wars.war_id=".$prefix."wars_participants.war_id 
	LEFT JOIN `".$prefix."alliance_members` ON ".$prefix."alliance_members.alliance_user_id=".$prefix."wars_participants.participant_user_id 
	LEFT JOIN `".$prefix."alliance` ON ".$prefix."alliance.alliance_id=".$prefix."alliance_members.alliance_id 
	LEFT JOIN `".$prefix."users` ON ".$prefix."users.user_id=".$prefix."wars_participants.participant_user_id 
WHERE ".$prefix."alliance.name LIKE '%$search%' OR ".$prefix."users.user_name LIKE '%$search%' GROUP BY ".$prefix."users.user_id
ORDER BY ".$SORT_CONFIG[$sort]." ".$DIR_CONFIG[$dir]." LIMIT $start,$results";

 

Is there some way I can have "sub querries" or something like that, so the results from one user is in an array inside the larger war array?

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.