Page 1 of 1

Horizontal results

Posted: Fri Nov 14, 2003 2:55 am
by fun4shor
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

Posted: Fri Nov 14, 2003 3:23 am
by twigletmac
What's the display code that you have currently?

Mac

Posted: Fri Nov 14, 2003 3:58 am
by igoy
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>

Posted: Fri Nov 14, 2003 5:00 am
by fun4shor
twigletmac wrote:What's the display code that you have currently?

Mac
$db = MYSQL_CONNECT("localhost",xxxxx,yyyyy) OR DIE ("Unable to connect to database");
@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";
}



?>

Posted: Fri Nov 14, 2003 12:33 pm
by Weirdan
You do not format your html output, so how it displays depends on browser used. Try Igoy suggestion to display your images in the table (you can always set border=0 to hide the table).

Thanks!!!!

Posted: Sat Nov 15, 2003 4:48 am
by fun4shor
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>

Posted: Sat Nov 15, 2003 8:25 am
by pootergeist
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)). '">&nbsp;</td></tr>' : '';