1) i fetch data from database suppose $data contains all the data of table A

from $data first two goes to below div
<div> //bgcolor green     
echo $data['a'];
echo $data['a'];
</div>

next 2 data to below div
<div>//bgcolor yellow
echo $data['a'];
echo $data['a'];
</div>

again next two data to 
<div> //bgcolor green     
echo $data['a'];
echo $data['a'];
</div>

again next two data to 
<div>//bgcolor yellow
echo $data['a'];
echo $data['a'];
</div>

like this how to implement in php???

Recommended Answers

All 2 Replies

PHP is an object oriented language based upon C++. It is most useful, and secure, when used that way. You save your HTML and JavaScript strings in class variables, and then output them when appropriate. DO NOT mix your HTML/JS code with PHP! That is a quick road to perdition.

commented: Good advice +15
Member Avatar for diafol

Keep html/php to a minimum. This is a bit rough, but you could do something like:

$cols = ['bgGreen','bgYellow','bgBlue']; //etc etc
$cnt = count($cols);
$i = 0;
$output = '';
foreach($data as $d){
    if($i == $cnt)$i=0;
    $output .= "\n<div class='$cols[$i]'>$d[0] $d[1]</div>";
    $i++;
}

Then...

echo $output;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.