嗨,我有一个sql数据库表,其中包含一些图像和一些描述。我需要能够显示一切但不能正常工作。我有两个不同的页面。所有数据库人员都在哪里和索引页面。这是第一页的功能
function get_image() {
global $db;
$query = 'SELECT * FROM table ';
try {
$statement = $db->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$statement->closeCursor();
return $result;
} catch (PDOException $e) {
$error_message = $e->getMessage();
display_db_error($error_message);
}
这是index.php:
//on the index page i set up an array to display all the images but all i get is a 404 not found. this is the index page
<?php
require_once('model/database.php');
require_once('model/image_db.php');
// Set the array to display the images
$image_ids = array(1,2,3,4,5);
$images = array();
foreach ($image_ids as $image_id) {
$image = get_image();
$images[] = $image; // add images to array
}
// Display the home page
include('home_view.php');
?>
并在主页上显示所有内容但未显示任何想法
<table>
<?php foreach ($images as $image) :
// Get image data
$imaget_price = $image['Price'];
$description = $image['description'];
// Get first paragraph of description
$description = add_tags($description);
$i = strpos($description, "</p>");
$description = substr($description, 3, $i-3);
?>
<tr>
<td id="image_column">
<img src="images/<?php echo $image['ID']; ?>.jpg"
alt=" ">
</td>
</tr>
<?php endforeach; ?>
</table>
?>
答案 0 :(得分:0)
修改强>
您将值绑定到不带值的查询。
$statement->bindValue(1, $image_id);
你可能想要这样的东西:
$query = 'SELECT * FROM table WHERE image_id = ?';