Link to home
Create AccountLog in
Avatar of Pete Winter
Pete WinterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Count - Every 4 item add style

I want to add a style every for items.

For example:

1) <div class="printer_block"></div>
2) <div class="printer_block"></div>
3) <div class="printer_block"></div>
4) <div class="printer_block" style="margin-right:0px;"></div>
5) <div class="printer_block"></div>
6) <div class="printer_block"></div>
7) <div class="printer_block"></div>
8) <div class="printer_block" style="margin-right:0px;"></div>
9) <div class="printer_block"></div>
10) <div class="printer_block"></div>
11) <div class="printer_block"></div>
12) <div class="printer_block" style="margin-right:0px;"></div>

How can I do this using php?
ASKER CERTIFIED SOLUTION
Avatar of Abhijeet Rananaware
Abhijeet Rananaware
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Pete Winter

ASKER

Many thanks
See http://www.laprbass.com/RAY_temp_petewinter.php 
Man pages:
http://php.net/manual/en/language.operators.arithmetic.php (modulus)
http://php.net/manual/en/language.operators.comparison.php (ternary)

<?php // RAY_temp_petewinter.php
error_reporting(E_ALL);
echo '<pre>';

// THE OUTPUT HTML DOCUMENT
$out = NULL;

// THE LIMITERS ARE COUNTERS
$num = 0;
$max = 9;

// THE "REAL LIFE" WHILE() WILL PROBABLY TEST FOR PRESENCE OF DATA INSTEAD OF COUNT
while ($num < $max)
{
    $num++;

    // USE TERNARY OPERATOR AND MODULUS TO CHOOSE STATEMENT
    $tag = ($num%4)
         ? '<div class="printer_block"></div>'
         : '<div class="printer_block" style="margin-right:0px;"></div>'
         ;
    $out .= $tag . PHP_EOL;
}

// SHOW THE WORK PRODUCT
echo htmlentities($out);

Open in new window

Best regards, ~Ray
Thanks for your addition help Ray.