display only 3 foreach result per row

Keep a counter, and output a new table row every 3 images

$output="<table class="products">"; 

$counter = 0;
while($info = mysql_fetch_array( $data )) 
{  
    if( $counter % 3 == 0 )
        $output .= '<tr>';

    $output .= "<td>";
    $output .= "<img src=http://localhost/zack/sqlphotostore/images/".$info['photo'] ." width=323px ></img>";
    $output .= "<b>Name:</b> ".$info['name'];
    $output .= "<b>Email:</b> ".$info['email'];
    $output .= "<b>Phone:</b> ".$info['phone']."</td> ";

    if( $counter % 3 == 0)
         $output .= "</tr>";

    $counter++;
}
$output.="</table>";
print $output;
?>

Leave a Comment