Page 1 of 1

placing images in rows

Posted: Sat Oct 23, 2004 4:01 pm
by dieselx42
Hi I am kind of new to php, usually use cfm for my sites.

Well what I am trying is to recreate a shopping cart I have. I have managed to generate the product image, name and price, but I am running into problems getting the products to go under to the next row after the fourth one is placed.

thanks,

Phil

Code: Select all

<?php
<table width="552" border="0" cellspacing="0" cellpadding="0">
  <tr>
			<td width="138" > 
			<?php $x = 0; while($list = mysql_fetch_array($result[result])){ ?> 
			<?php $array = $list[pPhoto] ? $db->scalePhoto($list[pPhotoWidth], $list[pPhotoHeight]) : array("width" => "75", "height" => "75"); ?>
			<table width="120" height="100%" border="0" cellpadding="0" cellspacing="0" class="borderSide" >
			  <tr>
				<td width="138" height="45" valign="top"> <div align="center">
				  <a href="<?php print $PHP_SELF; ?>?m=product_detail&p=<?php print $list[pID]; ?>"><img src="<?php print $db->productIMGurl; ?>/<?php $list[pPhoto] ? print $list[pPhoto] : print "na.gif"; ?>" width=<?php print $array[width]; ?> height=<?php print $array[height]; ?> border=0></a></span></div></td>
			  </tr>
			  <tr>
				<td height="25" valign="top">
				<!-- Product Name -->
				<span class="arial11bold"><b>
				<a href="<?php print $PHP_SELF; ?>?m=product_detail&p=<?php print $list[pID]; ?>" class="link"><?php print stripslashes($list[pName]); ?></a></b></span>
				<span class="arial11Grey">
				<!-- Pricing -->
				<?php $list[pSalesPrice]>'0' && $list[pSale]=="Y" ? print " <br><b>Price:</b> <strike>\$$list[pPrice]</strike><br><b>Sale:</b> \$$list[pSalesPrice]</font> " : print "<br><b>Now:</b> \$$list[pPrice]"; ?></span></td>
			  </tr>
			  <tr>
				<td height="22" valign="bottom"><a href="<?php print $PHP_SELF; ?>?m=product_detail&p=<?php print $list[pID]; ?>"><img src="imgs/buy.gif" width="25" height="15" border="0"></a></td>
			  </tr>
			</table>
			<div align="center"></div></td>
			<td><?php $x++; } ?></td>
  </tr>
</table>

?>

Posted: Mon Oct 25, 2004 4:12 am
by Tubbietoeter
As far as I understand you, you need this logic:


$x=0;

while (get_mysql_results) {

if ($x==4) {
// print break
$x=0;
}

// print item

$x++
}

Posted: Mon Oct 25, 2004 11:11 am
by pickle
Or even simpler:

Code: Select all

$x = 0;
while(get_mysql_results)
{
    if($x%4 == 0)
    {
          //print break
     }
     //print item
}