Display Div tags after 4 results not from database

$a = 0;
while(){

if($a == 4){<div class="result"><p>}//Display after 4 results

$results .=''.$result.'';

if($a == 4){</p></div>}//Display after 4 results

$a++;
}

example:

<div class="result"><p>
result 1
result 2
result 3
result 4
</p></div>

<div class="result"><p>
result 5
result 6
result 7
result 8
</p></div>

<div class="result"><p>
result 9
result 10
result 11
result 12
</p></div>

try following logic

if($a%4==0)
{
?>
<div class="result"><p>
<?
$results .=''.$result.'';
?>
</p></div>
<?
}

This is what you should do:

//set counter
$a = 0;

while(){

//check if counter is at start (0)
if($a == 0){$results .= '<div class="result"><p>';}//Display at start of a block of 4 results

$a++;
$results .=''.$result.'';

if($a == 4){
//reset counter so it is as start again
$ = 0;
$results .= '</p></div>';
}//Display after 4 results

}

You need to count to 4 and then set it to 0 so that the code knows what the start is and what the end is.

Display Div tags after 4 results not from database

$a = 0;
while(){

if($a == 4){<div class="result"><p>}//Display after 4 results

$results .=''.$result.'';

if($a == 4){</p></div>}//Display after 4 results

$a++;
}

example:

<div class="result"><p>
result 1
result 2
result 3
result 4
</p></div>

<div class="result"><p>
result 5
result 6
result 7
result 8
</p></div>

<div class="result"><p>
result 9
result 10
result 11
result 12
</p></div>

<?php
$div = '<div class="result"><p>';
$divend = '</p></div>';

// $i has to 1 2 3 4 so i started it from 1
$i=1;

/* this $a is needed to set a counter where 4 results already displayed it is set to 1 again
to print the end tag */
$a=1;


$end=15;

while($i<$end){

/* when it become 5 $a is made 1 so that another start dive tag will be diplayed */
if($a==5){
$a = 1;
}

if($a==1){
print $div;
}

print 'result :'.$i;

if($i%4==0){
print $divend;
}


if($i==$end-1){
print $divend;
}


$i++;
$a++;
}
?>

thanks all

Thanks all

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.