【发布时间】:2025-12-31 13:00:12
【问题描述】:
下面的代码进行查询,然后遍历这些结果。我很难理解什么是“?”在那个查询中以及如何制作“?”动态的。
假设 name = "?"。我改变了 ?到我在函数 $ad_id 中添加的变量,但仍然不起作用。我基本上只需要查询数据库 WHERE name = a variable。但是这个简单的解决方案不起作用。注释行是我替换的。
任何帮助将不胜感激。如果您想知道这是我试图使其动态的代码,而不仅仅是拉取表格中的所有图像: https://github.com/blueimp/jQuery-File-Upload/wiki/PHP-MySQL-database-integration
protected function set_additional_file_properties($file) {
parent::set_additional_file_properties($file);
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$ad_id = '1';
//$sql = 'SELECT `id`, `type`, `title`, `description` FROM `'
//.$this->options['db_table'].'` WHERE `name`=?';
$sql = 'SELECT id, type, title, description FROM '.$this->options['db_table'].' WHERE name = '.'$ad-id'.';
$query = $this->db->prepare($sql);
$query->bind_param('s', $file->name);
$query->execute();
$query->bind_result(
$id,
$type,
$title,
$description
);
while ($query->fetch()) {
if ($description == $ad_id){
$file->id = $id;
$file->type = $type;
$file->title = $title;
$file->description = $description;
};
}
}
}
【问题讨论】: