Jump to content

2 queries inside same while statement?


Recommended Posts

And if a JOIN isn't possible, just use two loops.


One loop doing twice the work as two won't save you much processing power. Just a little bit of code. This snippet from the php.net website even dumps the result into an array in a single line.


Daniel Chcouri - 333222 +A-T+ gmail 02-Apr-2009 11:45

Fetching all the results to array with one liner:

$result = mysql_query(...); 
while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray)); 

Link to comment
Share on other sites

Thanks for the suggestions. As being fairly new to this I'm getting more and more confused lol. I'll see if I can make some of this work, otherwise I'll reply with the code I have so it is more clear what I am trying to achieve (there's usually a simple answer to my questions) :)

Link to comment
Share on other sites

Good luck. Feel free to ask about specific parts of code that you don't understand. If the PHP manual doesn't explain it well, volunteers like us will try to explain it in a different way for you

Link to comment
Share on other sites

After a look at this, I simply have no idea what to do with it  :wtf:


So here are some more info; I am trying to list some events by date. My problem is listing 2 events happening the same day where a "variable" can be 2 things.




As picture above shows team with id "21" is both attacker and defender on same date. (disregards war_ended date)


When showing the events, It should show the date, the defending team name if any, and the attacking team if any.


my query right now is:

$sql_getevent = "SELECT DATE(war_started) AS war_started, attacker_name, defender_name, won, lost FROM teamwar_info 
WHERE attacker=".$_GET['t']."
ORDER BY DATE(war_started) DESC ";
$rs_getevent = mysql_query($sql_getevent);


This will show the date the right team name of the team being attacked.

The next column should show the team name of the team ATTACKING (on picture it should be "Black Beards Crew" as this team is attacking the team with id 21.


Using above picture: Assume our team has id 21. The event list should show date: 2011-5-10, attacking (the team WE attack): Jack Sparrow, the team attacking US: Black Beards Crew.


How can I do this?


(I am sure this is confusing, so please ask and I'll try to further explain.)



Link to comment
Share on other sites


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.