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
https://forums.phpfreaks.com/topic/134276-solved-phphtml/
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
https://forums.phpfreaks.com/topic/134276-solved-phphtml/#findComment-699054
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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