我想做的是回显subjects table
的所有行。
P.S。最近安装了Xdebug,现在php记录错误但在这种情况下错误日志中没有错误。
我的功能看起来像那样。没有输出。
function genSubjectsList() {
global $db;
$stmt = $db->prepare("SELECT `id`, `subject` FROM `subjects`") or die($db->error);
$row = array();
stmt_bind_assoc($stmt, $row);
while ($stmt->fetch()) {
echo "<input type='checkbox' value='" . $row[0] . "' name='subjects' id='subjects'/>" . $row[1] . "\n";
}
$stmt->close();
}
这个功能有什么问题?
答案 0 :(得分:0)
试试这个(未经测试,从PHP.net收集):
function genSubjectsList()
{
global $db;
$row = array();
$stmt = $db->prepare("SELECT `id`, `subject` FROM `subjects`") or die($db->error);
$stmt->execute();
$stmt->bind_result($row);
while ($stmt->fetch()) {
echo "<input type='checkbox' value='" . $row[0] . "' name='subjects' id='subjects'/>" . $row[1] . "\n";
}
$stmt->close();
}
答案 1 :(得分:0)
这就是你所需要的一切。测试
function genSubjectsList() {
global $db;
$stmt = $db->prepare("SELECT `id`, `subject` FROM `subjects`") or die($db->error);
$stmt->execute() or die($stmt->error);
/* bind variables to prepared statement */
$stmt->bind_result($id, $subject) or die($stmt->error);
/* fetch values */
while ($stmt->fetch()) {
echo "<input type='checkbox' value='" . $id . "' name='subjects' id='subjects'/>" . $subject . "\n";
}
/* close statement */
$stmt->close();
}