Jump to content

Random grid


JTxx

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.