sam06 Posted November 25, 2008 Share Posted November 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 25, 2008 Share Posted November 25, 2008 If you show your whole loop... You can do something like <?php $i = 0; while($rows = mysql_fetch_assoc())//fill it in propers { if($i == 3) { echo "<br>"; $i =0; } echo $rows['stuff']; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 25, 2008 Share Posted November 25, 2008 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> Quote Link to comment Share on other sites More sharing options...
sam06 Posted November 26, 2008 Author Share Posted November 26, 2008 Thanks both of you, the second script was brilliant, I just added a few <BR>'s and it's brill What it looks like now: Brilliant, Thanks. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 26, 2008 Share Posted November 26, 2008 FYI, this is in the FAQ section http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment Share on other sites More sharing options...
webmaster1 Posted November 26, 2008 Share Posted November 26, 2008 Shouldn't they be rewarded with some of those free sweets of yours for helping you out. (and me too for pointing it out ) Tsk! Tsk! Didn't close the door on the way out either. Mark as solved. Quote Link to comment Share on other sites More sharing options...
sam06 Posted November 26, 2008 Author Share Posted November 26, 2008 Have done And if they lived in the UK and reg for an account, then I'll add a few points Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted November 26, 2008 Share Posted November 26, 2008 I live in the UK Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.