- Combine mysql query with sub query results into one PHP array
- while(eventQuery):
- if commentQueryResult;
- $array .= commentQueryResult;
- if forumPostQueryResult;
- $array .= forumPostQueryResult;
- if uploadItemQueryResult;
- $array .= uploadItemQueryResult;
- endwhile;
- return $array; // Combined returned results as one array
- $eventResult = mysql_query(
- 'SELECT userevent.event, userevent.eventId, userevent.friendId
- FROM userevent
- WHERE userevent.userId = 1 OR userevent.friendId = 1
- ORDER BY userevent.id DESC
- LIMIT 20'
- );
- while ($eventRow = mysql_fetch_row($eventResult)){
- if($eventRow[0] == 1){
- $result = mysql_fetch_array(mysql_query("
- SELECT forumRooms.id, forumRooms.title
- FROM forumPosts
- INNER JOIN forumRooms ON forumPosts.`forumTopic` = forumRooms.`id`
- WHERE forumPosts.id = '$eventRow[1]'"));
- }
- elseif($eventRow[0] == 2){
- $result = mysql_fetch_array(mysql_query("
- SELECT game.id, game.uriTitle, game.title
- FROM usergamecomment
- INNER JOIN game ON usergamecomment.`gameId` = game.id
- WHERE usergamecomment.id = $eventRow[1]"));
- }
- elseif($eventRow[0] == 4){
- $result = mysql_fetch_array(mysql_query("
- SELECT usercomment.comment, UNIX_TIMESTAMP(usercomment.TIME), `user`.id, `user`.username, `user`.activate
- FROM usercomment
- INNER JOIN `user` ON usercomment.`userId` = `user`.id
- WHERE usercomment.id = $eventRow[1]
- AND `user`.activate = 1"));
- }
- elseif($eventRow[0] == 5){
- $result = mysql_fetch_array(mysql_query("
- SELECT game.id, game.title, game.uriTitle
- FROM game
- WHERE game.id = $eventRow[1]"));
- }
- // Combined Results as array
- }
- $result = array();
- $q = 'SELECT userevent.event AS userevent_event,
- userevent.eventId AS userevent_eventId,
- userevent.friendId AS userevent_friendId,
- forumRooms.id AS forumRooms_id,
- forumRooms.title AS forumRooms_title,
- game.id AS game_id,
- game.uriTitle AS game_uriTitle,
- game.title AS game_title,
- usercomment.comment AS usercomment_comment,
- UNIX_TIMESTAMP(usercomment.TIME) AS usercomment_time,
- user.id AS user_id,
- user.username AS user_username,
- user.activate AS user_activate,
- g2.id AS game2_id,
- g2.uriTitle AS game2_uriTitle,
- g2.title AS game2_title
- FROM userevent
- LEFT JOIN forumPosts ON forumPosts.id = userevent.eventId
- LEFT JOIN forumRooms ON forumPosts.forumTopic = forumRooms.id
- LEFT JOIN usergamecomment ON usergamecomment.id = userevent.eventId
- LEFT JOIN game ON usergamecomment.gameId = game.id
- LEFT JOIN usercomment ON usercomment.id = userevent.eventId
- LEFT JOIN user ON usercomment.userId = user.id
- LEFT JOIN game g2 ON userevent.eventId = g2.id
- WHERE (userevent.userId = 1 OR userevent.friendId = 1)
- AND userevent.eventId >= (SELECT userevent.eventId
- WHERE userevent.userId = 1 OR userevent.friendId = 1
- ORDER BY userevent.id DESC LIMIT 1,20);';
- $r = mysql_query($q);
- while ( $o = mysql_fetch_row($r) ) {
- switch($o['userevent_event']) {
- case 1:
- $result[] = array(
- 'id' => $o['forumsRooms_id'],
- 'title' => $o['forumsRooms_title'],
- );
- break;
- case 2:
- $result[] = array(
- 'id' => $o['game_id'],
- 'uriTitle' => $o['game_uriTitle'],
- 'title' => $o['game_title'],
- );
- break;
- case 4:
- $result[] = array(
- 'comment' => $o['usercomment_comment'],
- 'time' => $o['usercomment_time'],
- 'id' => $o['user_id'],
- 'username' => $o['user_username'],
- 'activate' => $o['user_activate'],
- );
- break;
- case 5:
- $result[] = array(
- 'id' => $o['game2_id'],
- 'uriTitle' => $o['game2_uriTitle'],
- 'title' => $o['game2_title'],
- );
- break;
- }
- }