Jump to content

using a table to display results


ohdang888

Recommended Posts

heres the code i have right now, it works...

 

but how do i say, "after 5 results are displayed, then echo "'</tr>'.'<tr>'"".....????????

 

<table>
<tr>
<?php

mysql_connect("localhost", "----", "-----") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$new_games = mysql_query("SELECT link, game_picture_url, type, counter FROM game ORDER BY counter LIMIT 10")
or die(mysql_error());  

while($row2 = mysql_fetch_assoc($new_games)){       
   echo '<td>';
   echo'<center>';
   echo '<font size=3>';
   echo '<img src="gamepic/';
   echo $row2['game_picture_url'];
   echo '" height="120" width="120"><br>';
   echo $row2['link'].'<br>';
   echo '<font size=2>';
   echo '(';
   echo $row2['type'];
   echo ')';
   echo '</td>';
}


?>
</tr>

Link to comment
https://forums.phpfreaks.com/topic/84180-using-a-table-to-display-results/
Share on other sites

I prefer the modulus method:

 

$x = 0;

echo '<tr>';

while($row2 = mysql_fetch_assoc($new_games)){       
   if ($x % 5 == 0) {
     echo '</tr><tr>';
   }
   $x++;

   echo '<td>';
   echo'<center>';
   echo '<font size=3>';
   echo '<img src="gamepic/';
   echo $row2['game_picture_url'];
   echo '" height="120" width="120"><br>';
   echo $row2['link'].'<br>';
   echo '<font size=2>';
   echo '(';
   echo $row2['type'];
   echo ')';
   echo '</td>';
}

 

However, there are, of course, many others.

would i still need to put

 

 

</tr> after the whole php code??????????

 

 

example of what i',m talking about...

 


<?php

mysql_connect("localhost", ----", "---") or die(mysql_error());
mysql_select_db("games") or die(mysql_error());

$new_games = mysql_query("SELECT link, game_picture_url, type, date_added FROM game ORDER BY date_added LIMIT 10")
or die(mysql_error());  

$x = 0;

echo '<tr>';

while($row2 = mysql_fetch_assoc($new_games)){       
   if ($x % 5 == 0) {
     echo '</tr><tr>';
   }
   $x++;

   echo '<td>';
   echo'<center>';
   echo '<font size=3>';
   echo '<img src="gamepic/';
   echo $row2['game_picture_url'];
   echo '" height="120" width="120"><br>';
   echo $row2['link'].'<br>';
   echo '<font size=2>';
   echo '(';
   echo $row2['type'];
   echo ')';
   echo '</td>';
}


?>
</tr> <!--DO I NEED THIS?-->

yes, you would still need it...and something to fill out any remaining td's to make the rows even:

 

$x = 0;

echo '<tr>';

while($row2 = mysql_fetch_assoc($new_games)){       
   if ($x % 5 == 0) {
     echo '</tr><tr>';
   }
   $x++;

   echo '<td>';
   echo'<center>';
   echo '<font size=3>';
   echo '<img src="gamepic/';
   echo $row2['game_picture_url'];
   echo '" height="120" width="120"><br>';
   echo $row2['link'].'<br>';
   echo '<font size=2>';
   echo '(';
   echo $row2['type'];
   echo ')';
   echo '</td>';
}

while ($x < 5) {
   echo '<td> </td>';
   $x++;
}

echo '</tr>';

 

The part to fill out the row should be necessary with any implementation to keep your html "proper".

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.