Hi everyone. I am in desperate, desperate need of help here. I'm trying to split my while loop into two columns. How do you do that?
Here is my exact code:
---
echo '
<table align="left" cellspacing="0" cellpadding="0" id="wording">
';
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "
<tr>
<td><img src=\"show_image.php?image={$row['thumbnail']}\"></img></td>
<td width=\"20px\"></td>
</tr>
";
}
mysql_free_result ($result);
echo '</table>';
---
Thank so much...really need help...
Need help dividing while loop into two columns...
Moderator: General Moderators
-
RiceDaddy7
- Forum Newbie
- Posts: 2
- Joined: Fri Oct 24, 2008 5:02 pm
Re: Need help dividing while loop into two columns...
I use a method where you first get the array, then use a for loop on it. Example:
Should work fine for what you're trying to do.
[EDIT] If you're using an associative array, try this:
Code: Select all
<?php
$array = array( "foo", "bar", "baz", "foobar" );
for( $i = 0; $i < count( $array ); $i += 2 )
{
?>
<tr>
<td><?php echo $array[$i]; ?></td>
<?php if( isset( $array[$i+1] ) ) { ?>
<td><?php echo $array[$i+1]; ?></td>
<?php } ?>
</tr>
<?php } ?>[EDIT] If you're using an associative array, try this:
Code: Select all
<?php
$mysql_array = mysql_fetch_array( $result, MYSQL_ASSOC );
$array = array_keys( $mysql_array );
for( $i = 0; $i < count( $array ); $i += 2 )
{
?>
<tr>
<td><?php echo $mysql_array[$array[$i]]; ?></td>
<?php if( isset( $array[$i+1] ) ) { ?>
<td><?php echo $mysql_array[$array[$i+1]]; ?></td>
<?php } ?>
</tr>
<?php } ?>-
RiceDaddy7
- Forum Newbie
- Posts: 2
- Joined: Fri Oct 24, 2008 5:02 pm
Re: Need help dividing while loop into two columns...
Is there a way to do this on a while loop though instead of an array? I have already have the code perfected as a while loop on single column format. I do not want to overhaul. Can someone please help?