我有此代碼以5行顯示我的圖像,但由於某些原因,代碼在第一行的末尾添加了圖像。在行中顯示圖像
這段代碼有錯誤嗎?如果不是,我該如何改變它以停止在第一行末尾添加額外的圖像。
代碼:
$query = mysql_query("SELECT * FROM gallery WHERE gallery_number='$gallery_number'");
echo '<table width="960">';
$i = 0; //first, i set a counter
while($fetch = mysql_fetch_assoc($query)){
//counter is zero then we are start new row
if ($i==0){
echo '<tr>';
}
//here we creating normal cells <td></td>
$image_name = $fetch['image_name'];
$image_location = $fetch['image_location'];
echo '<td>'.'<img src="'.$image_location.'" alt="'.$image_name.'"/>'.'</td>';
//there is a magic - if our counter is greater then 5 we set counter to zero and close tr tag
if ($i>5){
$i=0;
echo '</tr>';
};
$i++; //$i = $i + 1 - counter + 1
}
echo '</table>';