我的函數看起來像這樣。PHP取數據兩次
private function generateTree($courseID) {
$q = "SELECT l.id, l.name AS lesson_name, c.name AS course_name FROM lessons AS l, courses AS c WHERE l.course_id=c.id AND c.id=?";
$stmt = $this->db->prepare($q);
$stmt->bind_param("i", $courseID);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $lName, $cName);
echo "<li> <a href='#'>$cName</a> <ul>";
while ($stmt->fetch()) <====HERE!!!
echo "<li> <a href='?course=$courseID&lesson=$id'> $lName </a></li>";
echo "</ul> </li>";
}
}
問題是我開始在一段時間內獲取數據,但是我也需要它。我可以提取兩次數據嗎?還有其他建議嗎?
這不是PDO,而是事先聲明。另外,我如何循環使用fetchal呢? – heron 2012-07-17 16:33:25
@epic_syntax這裏是mysqli版本:http://php.net/manual/en/mysqli-result.fetch-all.php – Neal 2012-07-17 16:34:42
我正在使用PREPARED STATEMENTS – heron 2012-07-17 16:35:59