views:

56

answers:

4

MySQL

$selectSize     = "SELECT * FROM products";
$querySize      = $db->select($selectSize);
while ($product = $db->fetcharray($querySize)) {

HTML

<ul>
<li>Product A</li>
<li>Product B</li>
<li class='right'>Product C</li>
<li>Product D</li>
<li>Product E</li>
<li class='right'>Product F</li>
</ul>

Question

While getting the product, I want the Product C and Product F or any product after 3 loops will have class='right' to the list style. Let me know

Thanks

+2  A: 

Use something like the following (your code snippet was a little short)

$index = 1;
while ($product = $db->fetcharray($querySize)) {
    if ($index % 3 == 0) {
        //add your class here
    }
    $index++;
    //...
Jonathan Fingland
Thanks Jonathan Fingland. You rock!
bob
glad to help. Thanks for the accept.
Jonathan Fingland
+2  A: 

.

$count = 0;
while ($product = $db->fetcharray($querySize)) {
    echo "<li" . ((++$count % 3) ? "" : " class=\"right\"") . ">" 
        . $product['name']
        . "</li>\n";
}
nickf
A: 
Craiga
A: 

asadfasdfasdfasdfasdfasdf

Craiga