Php loop & lt; li & gt; & lt; ul & gt; & lt; li & gt; & lt; img & nbsp; src = "images/small_case_1.jpg" & nbsp; alt = ""/& gt; & lt;/li & gt; & lt; img & nbsp; src = "images/sm php loop
How can we cycle through the above form ....
------ Solution --------------------
$arr = array(
'images/small_case_1.jpg',
'images/small_case_2.jpg',
'images/small_case_3.jpg',
'images/small_case_4.jpg',
'images/small_case_5.jpg',
'images/small_case_6.jpg',
'images/small_case_7.jpg',
'images/small_case_8.jpg',
'images/small_case_9.jpg'
);
function arr2li($arr){
$html = '';
if(is_array($arr) && !empty($arr)){
$count = count($arr);
for($i=0; $i<$count; $i++){
$rem = $i%3;
$html .= ($i!=0 && $rem==0) ? "\n\r\n\r" : "";
$html .= ($rem==0) ? "
\n\r
\n\r" : "";
$html .= sprintf("
\n\r", $arr[$i]);
$html .= ($i+1==$count) ? "
\n\r" : "";
}
}
return $html;
}
/*
*/
echo arr2li($arr);
------ Solution --------------------
$result=mysql_query("select * from case_list");
while($row=mysql_fetch_assoc($result)){
$ar[]=$row;
}
foreach(array_chunk($ar,3) as $v){
echo "\n
\n";
foreach($v as $vl) echo "
\n";
echo "
\n\n";
}