我有一些問題產生,將來自PHP數據庫顯示圖像成表上的PHP
顯示圖片的表這是我的代碼:
$query = "SELECT * FROM images ORDER BY name ASC ";
$result = $db->query($query);
$num_result = $result->num_rows;
echo "<h1> Images</h1>";
$array = array();
for ($i = 0; $i < $num_result; $i++){
$row = $result->fetch_assoc();
$name = $row['name'];
$URL = $row['imageURL'];
$array[] = $URL;
}
//this loop is printing the images correctly in order
foreach ($array as $image){
echo '<img src="'.$image.'"/>';
}
我試圖做到的是創建一個2列的列表,將打印圖像那裏,像這樣的東西
echo '<table>';
echo ' <tr>';
echo ' <td>image 1</td>';
echo ' <td>image 2</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td>image 3</td>';
echo ' <td> image 4</td>';
echo ' </tr>';
// and so on if there is more images
echo '</table>';
任何建議將有助於,謝謝!
檢查了這一點:http://www.php.net/manual/en/language.operators.arithmetic.php#70424此外,一定要使用' htmlspecialchars()'圍繞在HTML上下文中使用的任意數據。否則,您將冒險生成無效的HTML甚至可能發生注入式攻擊。 'echo'
';' –
Brad