FMATeam Posted March 28, 2009 Share Posted March 28, 2009 Hey Got a small problem. I have a MySQL database with game data in it and i'm trying to display the data 3 columns in a row before moving to the next row. right now the data appears like so. Fig 1 1 2 3 4 5 6 7 and i'd like it to appear like this: Fig 2 1 2 3 4 5 6 7 8 9 each number above is a consecutive row from the database. Any help on this is much appreciated> Below is the code I already written but shows the data in the format in Fig 1. How do I modify the below code so that it will display in the format as shown in Fig 2? <?php $con = mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('critical', $con); $genre = mss($_GET['genre']); $sql = "SELECT * FROM `genre` WHERE `urlid`='" . $genre . "'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0) { $row = mysql_fetch_assoc($res); echo $row['genre']; $sql2 = "SELECT * FROM `genre` WHERE `genre`='" . $genre . "'"; $return = mysql_query($sql2) or die(mysql_error()); ?> <table width="50%" border="0"> <?php $i = 0; while ($data = mysql_fetch_array($return)) { ?> <tr> <?php if($i % 3 == 0) ?> <td> <img width="70" height="70" src="images/<?php echo $data['gamepic']; ?>"><br /> <?php echo $data['gamelink']; ?> </td> <?php $i++; ?> </tr> <?php } ?> </table> <?php } else { echo "Please select a genre"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151471-solved-display-data-from-three-rows/ Share on other sites More sharing options...
ratcateme Posted March 28, 2009 Share Posted March 28, 2009 <table width="50%" border="0"> <tr> <?php $i = 0; while ($data = mysql_fetch_array($return)) { ?> <?php if($i != 0 && $i % 3 == 0){ echo "</tr> <tr>"; }?> <td> <img width="70" height="70" src="images/<?php echo $data['gamepic']; ?>"><br /> <?php echo $data['gamelink']; ?> </td> <?php $i++; ?> <?php } ?> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/151471-solved-display-data-from-three-rows/#findComment-795597 Share on other sites More sharing options...
FMATeam Posted March 28, 2009 Author Share Posted March 28, 2009 Excellent Thank You Quote Link to comment https://forums.phpfreaks.com/topic/151471-solved-display-data-from-three-rows/#findComment-795600 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.