[Solved] how to show div alternately


As I understand, you are asking how to determine the alternate divs for applying different styles.

You should use CSS classes to give the divs alternate effect.

.section{width:500px; height:200px;}
.rightinfo{ float : right; }
.leftinfo{ float : left; }
.section img{width:402px; height:178px;}

In your PHP code before while loop have a variable

$style = 0;

and in while loop increment and check the value (odd / even) for applying correct classes.

$style++;
if($style % 2 == 0){
    $imgClass="leftinfo";
    $descClass="rightinfo";
} else {
    $imgClass="rightinfo";
    $descClass="leftinfo";
}

assign these classes to your HTML elements.

<div class="<?php echo $imgClass; ?>"> .... </div>
<div class="<?php echo $descClass; ?>"> .... </div>

Example Fiddle

0

solved how to show div alternately