Jump to content

[SOLVED] PHP/HTML


sam06

Recommended Posts

Currently I am displaying sweets in my virtual shop/checkout one on top of the other, however I would like to change this to 2 or maybe 3 on a row.

 

My code currently is:

	echo '<tr><td width="384" height="25" align="center">'; 
echo '<font color="#FFFFFF" face="Arial" size="4">'.$row['name'].'</font>';
echo '</td></tr><tr><td width="384" height="150" align="center">'; 
echo '<img border="0" src="'.$row['image'].'">';
echo '</td></tr><tr><td width="384" height="25" align="center">'; 
echo '<a href="addsweets.php?id='.$row['id'].'&user='.$username.'" class="external">Buy for '.$row['points'].' Points</a>';
echo "</td></tr>"; 

 

Is this possible?

 

Cheers,

Sam

Link to comment
Share on other sites

This is untested, so might math may be wrong, but this should display in a table with 3 columns.

 

<?php
$x = 1;
$columns = 3;
?>
<table>
<?php while ($row = mysql_fetch_assoc($result)): ?>

	<?php if (($x - 1) % $columns == 0): ?>
		<tr>
	<?php endif; ?>

	<td width="384" height="25" align="center">
		<font color="#FFFFFF" face="Arial" size="4"><?php echo $row['name'] ?></font>
		<img border="0" src="<?php echo $row['image'] ?>">
		<a href="addsweets.php?id=<?php echo $row['id'] ?>'&user=<?php echo $username ?>" class="external">
			Buy for <?php echo $row['points'] ?> Points
		</a>
	</td> 

	<?php if ($x % $columns == 0): ?>
		</tr>
	<?php endif; ?>

	<?php $x++ ?>

<?php endwhile; ?>
</table>

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.