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> '; } Link to comment https://forums.phpfreaks.com/topic/196111-changing-div-class-in-while-loop/ 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++; Link to comment https://forums.phpfreaks.com/topic/196111-changing-div-class-in-while-loop/#findComment-1029937 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.