placing images in rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dieselx42
Forum Newbie
Posts: 5
Joined: Thu Oct 21, 2004 10:41 pm

placing images in rows

Post 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>

?>
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post 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++
}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Or even simpler:

Code: Select all

$x = 0;
while(get_mysql_results)
{
    if($x%4 == 0)
    {
          //print break
     }
     //print item
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply