jigsawsoul Posted March 22, 2010 Share Posted March 22, 2010 Work's perfect and displays all the products, but i need the div class, productDetailsPH to change to productDetailsPH-1 on every other result. to end up with this result, grey background white background grey background white background etc... I'm quite new to php and i'm unsure how i would go about creating something like this, any help guys.. ? $result = "SELECT * FROM products"; $result = mysql_query ($result) or die (mysql_error()); while($row = mysql_fetch_assoc($result)) { $products .= ' <div class="postHoplder"> <div class="productName">'.$row['title'].'</div> <div class="productDetailsPH"> <div class="fltlft"><img src="_img/products/'.$row['image1'].'" alt="" width="122" height="81" /></div> <div class="PicDetailsPH"> <p>'.substr($row['description'], 0, 230).'... <a href="product.php?id='.$row['id'].'">read more</a></p> </div> <div class="payholderPH"> <a href="#">Add to Cart</a> <p>£ '.$row['price'].'</p> </div> </div> </div> '; } Quote Link to comment Share on other sites More sharing options...
scvinodkumar Posted March 22, 2010 Share Posted March 22, 2010 its very simple, add the below code definition above while loop $i=0; and add this code below the 'while {' code if($i%2) $divclass = 'productDetailsPH'; else $divclass = 'productDetailsPH-1'; and replace this line <div class="productDetailsPH"> to <div class="'.$divclass.'"> at the end of the while loop $i++; 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.