chriscloyd Posted May 16, 2007 Share Posted May 16, 2007 Heres my dilemma. I have a script that is going to make a roster image that shows all the members on the team and I need to do rows of three. So I have 9 images And i need to do three columns and then when it gets to the third image to make a new row how would i Do this? Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 I am sorry, but I can't understand what you want. Perhaps you could give an example or show some code? Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 well heres an example go to www.team3d.com and look on the right side where it has the pics of the members Okay let me try to explain better. I have 9 users on my clan roster. I need to show all their pics and i dont want to show all in one row or all on separate rows i wanna show them in rows of three once it hits three create a new row and display three more then once it hits six new row and display three more Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 I think that makes perfect sense now lol Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 Oh So lets say we have their names or whatever in an array called $names: <?php $i = 0 echo "<table>"; foreach($names as $name) { if($i % 3 == 0) echo "<tr>"; echo "<td>".$name."</td>"; if($i % 3 == 0) echo "</tr>"; $i++ } //Just to make sure we are closing the last <tr> if(($i-1) % 3 != 0) echo "</tr>"; echo "</table>"; ?> Hope it helps, Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 well how would i put there name into an array here would i do this <?php $game_id = $_GET['game']; $names = array(); $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); while($roster = mysql_fetch_array($get_roster)) { $i = 0; $names[] = $roster['displayname']; foreach($names as $name) { if($i % 3 == 0) { echo "<tr>"; } echo "<td>".$name."</td>"; if($i % 3 == 0) { echo "</tr>"; } $i++; } //Just to make sure we are closing the last <tr> if(($i-1) % 3 != 0) echo "</tr>"; } ?> i tried that and it didnt work Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 In your case it should be: <?php $game_id = $_GET['game']; $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); echo "<table>"; $i = 0; while($roster = mysql_fetch_array($get_roster)) { if($i % 3 == 0) { echo "<tr>"; } echo "<td>".$roster['displayname']."</td>"; if($i % 3 == 0) { echo "</tr>"; } $i++; } if(($i-1) % 3 != 0) echo "</tr>"; } echo "</table>"; ?> Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 heres what im trying right now and its not working <?php $game_id = $_GET['game']; $i = 0; echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">'; $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); while($roster = mysql_fetch_array($get_roster)) { $i++; $get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'"); $user = mysql_fetch_array($get_user); if ($i % 3) { echo '<tr>'; } echo '<td><img src="'.$user['picture'].'"></td>'; if ($i % 3) { echo '</tr>'; } } echo '</table>'; ?> http://chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 its showing it on three separate lines Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 Yeah my mistake: <?php $game_id = $_GET['game']; $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); echo "<table><tr>"; $i = 0; while($roster = mysql_fetch_array($get_roster)) { echo "<td>".$roster['displayname']."</td>"; if($i % 3 == 0) { echo "</tr><tr>"; } $i++; } if(($i-1) % 3 != 0) echo "</tr>"; } echo "</table>"; ?> Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 tried that too now shows two on each row <?php $game_id = $_GET['game']; $i = 0; $get_game = mysql_query("SELECT * FROM games WHERE game_id = '".$game_id."'") or die(mysql_error()); $game = mysql_fetch_array($get_game); echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">'; echo '<tr>'; echo '<td align="center" colspan="3">'.$game['gamename'].'</td>'; echo '</tr>'; echo '<tr>'; $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); while($roster = mysql_fetch_array($get_roster)) { $get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'"); $user = mysql_fetch_array($get_user); echo '<td><img src="'.$user['picture'].'" height="65px" width="65px"></td>'; if ($i % 3) { echo '</tr><tr>'; } $i++; } echo '</table>'; ?> http://chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 You changed the code. It's supposed to be: if($i % 3 == 0) and not if($i % 3) Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 it doesnt effect it Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 Show me the output and the updated script again please. Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 <?php $game_id = $_GET['game']; $i = 0; $get_game = mysql_query("SELECT * FROM games WHERE game_id = '".$game_id."'") or die(mysql_error()); $game = mysql_fetch_array($get_game); echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">'; echo '<tr>'; echo '<td align="center" colspan="3">'.$game['gamename'].'</td>'; echo '</tr>'; echo '<tr>'; $get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error()); while($roster = mysql_fetch_array($get_roster)) { $get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'"); $user = mysql_fetch_array($get_user); echo '<td align="center"><img src="'.$user['picture'].'" height="65px" width="65px"></td>'; if ($i % 3) { echo '</tr><tr>'; } $i++; } echo '</tr>'; echo '</table>'; ?> http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 lol change the line $i=0 to $i=1 Orio. Quote Link to comment Share on other sites More sharing options...
chriscloyd Posted May 16, 2007 Author Share Posted May 16, 2007 just did that now it changes it back to this http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1 Quote Link to comment Share on other sites More sharing options...
Orio Posted May 16, 2007 Share Posted May 16, 2007 Thats what you wanted right? Orio. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.