JTxx Posted June 15, 2009 Share Posted June 15, 2009 First of all, please help! Ok so im trying to create a table of 4 columns and 3 rows with each cell holding a random hyperlinked picture. Below is my code. <?php include ("connection.php"); $query = "SELECT * FROM games ORDER BY Rand() LIMIT 3"; $result = mysql_query($query); print "<table border=1>"; while($row = mysql_fetch_array($result)) { print "<tr>"; print "<td><a href=pregame.php?id=".$row['GameId']."><img src=images/".$row['Thumb']." alt=Image width=100 height=76 class=gamepic/></a></td>"; print "<td><a href=pregame.php?id=".$row['GameId']."><img src=images/".$row['Thumb']." alt=Image width=100 height=76 class=gamepic/></a></td>"; print "<td><a href=pregame.php?id=".$row['GameId']."><img src=images/".$row['Thumb']." alt=Image width=100 height=76 class=gamepic/></a></td>"; print "<td><a href=pregame.php?id=".$row['GameId']."><img src=images/".$row['Thumb']." alt=Image width=100 height=76 class=gamepic/></a></td>"; print "</tr>"; } print "</table>"; ?> The problem is that its printing the same hyperlinked picture in each 4 cells of a row. Link to comment https://forums.phpfreaks.com/topic/162244-random-grid/ Share on other sites More sharing options...
Mark Baker Posted June 15, 2009 Share Posted June 15, 2009 The problem is that its printing the same hyperlinked picture in each 4 cells of a row. Yes it will, because you're telling it to print exactly the same thing in each cell for the row. include ("connection.php"); $query = "SELECT * FROM games ORDER BY Rand() LIMIT 12"; $result = mysql_query($query); $i = 0; print "<table border=1>"; while($row = mysql_fetch_array($result)) { if (($i % 4) == 0) print "<tr>"; print "<td><a href=pregame.php?id=".$row['GameId']."><img src=images/".$row['Thumb']." alt=Image width=100 height=76 class=gamepic/></a></td>"; if (($i++ % 4) == 3) print "</tr>"; } print "</table>"; Link to comment https://forums.phpfreaks.com/topic/162244-random-grid/#findComment-856255 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.