Jump to content

[SOLVED] Display data from three rows


FMATeam

Recommended Posts

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/151471-solved-display-data-from-three-rows/
Share on other sites

<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>

 

 

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.