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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.