If anyone can help I'd really appreciate it.
I'm looking how to display my results horizontally.
I am pulling 4 records from a database (that part is done) and want to display those results in a table with 4 colums.
Can anybosy give some advice?
Thanks
Horizontal results
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
simple....
if you are doing something like this for rows...
.... then to have it in columns, all you have to do is... loop <TD> instead of <TR>..
if you are doing something like this for rows...
Code: Select all
<?php do { ?>
<tr>
<td><?php echo $row_rsSomething['record'] ?></td>
</tr>
<?php } while ($row_rsSomething = mysql_fetch_rows($result)) // this is just a example of condition?>.... then to have it in columns, all you have to do is... loop <TD> instead of <TR>..
Code: Select all
<tr>
<?php do { ?>
<td><?php echo $row_rsSomething['record'] ?></td>
<?php } while ($row_rsSomething = mysql_fetch_rows($result)) // this is just a example of condition ?>
</tr>$db = MYSQL_CONNECT("localhost",xxxxx,yyyyy) OR DIE ("Unable to connect to database");twigletmac wrote:What's the display code that you have currently?
Mac
@mysql_select_db(attorney_images,$db) or die ("Unable to select database");
$result = mysql_query("SELECT * FROM accidents order by RAND()LIMIT 4");
if($myrow = mysql_fetch_array($result))
{
do{
echo"<img src=http://website.com/images/attorneys/$myrow[0]>";
}while ($myrow = mysql_fetch_array($result));
}else{
echo "bad image";
}
?>
Thanks!!!!
Thanks a lot it works just fine!!!
igoy wrote:simple....
if you are doing something like this for rows...
Code: Select all
<?php do { ?> <tr> <td><?php echo $row_rsSomething['record'] ?></td> </tr> <?php } while ($row_rsSomething = mysql_fetch_rows($result)) // this is just a example of condition?>
.... then to have it in columns, all you have to do is... loop <TD> instead of <TR>..
Code: Select all
<tr> <?php do { ?> <td><?php echo $row_rsSomething['record'] ?></td> <?php } while ($row_rsSomething = mysql_fetch_rows($result)) // this is just a example of condition ?> </tr>
-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
If the number of returned results was dynamic and you still wanted a set number of TDs, you would want additional coding to throw in a </tr><tr> pair at every NN iterations (and a clause to add an empty <td> with colspan for the last row)
Code: Select all
$tmp_cnt = 0; // temporary variable
$per_row = 4; // number of <td>s per <tr>
echo '<table border="0" cellpadding="2" cellspacing="1">';
while($row = mysql_fetch_array($result)) {
// echo a <tr> if tmp_cnt/per_row leaves a remainder of 0
echo (($tmp_cnt %$per_row == 0) ? '<tr>' : '');
// here we output our <td> and looped information
echo '<td><img src="images/' .$row['img_location']. '" /></td>';
// echo a closing </tr> if pre-incremented tmp_cnt/per_row leaves a remainder of 0
echo ((++$tmp_cnt %$per_row == 0) ? '</tr>' : '');
}
// loop now finished - so conditionally add a colspan <td> for the last <tr>
echo ($tmp_cnt %$per_row !== 0) ? '<td colspan="' .($per_row - ($tmp_cnt % $per_row)). '"> </td></tr>' : '';