Author Topic: This code is wrong. I need help  (Read 5160 times)

0 Members and 1 Guest are viewing this topic.

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
This code is wrong. I need help
« on: December 03, 2009, 11:28:02 PM »
Hello,

I need some help in this code:

I added a column to my database: image_game
I created also a new tabel: zu_games (zu_game_id, zu_games_game..)

For example: I have 10 images on my galery. 5 images from the game1 and 5 images from the game2. So the field image_game has the value game1. And also the other 4 image_game. Clear?
As result I want something like:
GamesImage ids
Game11, 2, 3, 4, 5
Games26, 7, 8, 9, 10

With the following code I got this result. That means he get only 1 image id instead of everything.

GamesImage ids
Game11
Games26

Code: [Select]
$sql = "SELECT *, i.image_id, i.image_game
        FROM (".ZU_GAMES_TABLE." g)
LEFT JOIN (".IMAGES_TABLE." i) ON (i.image_game = g.zu_games_game)
        WHERE zu_games_game LIKE '%$zu_games_team1%' AND zu_games_game LIKE '%$zu_games_team2%'
GROUP BY zu_games_game
ORDER by g.zu_games_date ASC
";
        
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
   $zu_game_teams_games = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\"><tr><td>No info</td></tr>";
}
else  {
    $zu_game_teams_games = "<table class=\"head2\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    <tr><td><b>#</b></td>
<td><b>Date</b></td>
<td><b>Game</b></td>
<td><b>Videos</b></td>
</tr>
    ";
    
   $i = 1;
   while ($zu_games_row = $site_db->fetch_array($result)){  
  
   $zu_games_date = date("d-m-Y", $zu_games_row['zu_games_date']);  
   $day = substr($zu_games_row['zu_games_day'], 0, 2);

   $image_game2 = "".$zu_games_row['image_id'].", ";
   $image_id_videos = substr($image_game2, 0, -2);
  
      $zu_game_teams_games .= "<tr>
 <td valign=\"top\" class=\"sortable\"><b>".$i++."</b></td>
      <td valign=\"top\">".$day." ".$zu_games_date."</td>
      <td valign=\"top\"><a href=\"".$site_sess->url(ROOT_PATH."zu_games.php?zu_games_id=".$zu_games_row['zu_games_id'])."\">".$zu_games_row['zu_games_game']."</a></td>
      <td>".$image_id_videos."</td>
      </td></tr>
   ";
}      
}
  $zu_game_teams_games .= "</table>\n";
  
$site_template->register_vars("zu_game_teams_games", $zu_game_teams_games);
unset($zu_game_teams_games);


I apreciate any help.

Cruxy

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: This code is wrong. I need help
« Reply #1 on: December 04, 2009, 01:29:36 AM »
What happens if you remove GROUP BY zu_games_game?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: This code is wrong. I need help
« Reply #2 on: December 04, 2009, 07:39:31 AM »
Thank you V@no for you reply.

We are almost there because now I get something like:

GamesImage ids
Game11
Game12
Game13
Game14
Game15
Games26
Games27
Games28
Games29
Games210

So I am getting all the image_id, but we have to group it to get them in one line.



Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: This code is wrong. I need help
« Reply #3 on: December 04, 2009, 08:28:40 AM »
that's how it's being done. You'll need load them into an array and then use that array to process the output data, or something like that.

$array[$zu_games_row['zu_games_game']] = $zu_games_row;
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)