我試圖根據用戶點擊的當前主題(主題稱爲會話)從測驗列表中顯示測驗。會議有練習,並且我希望每次練習都能參加特定的會話測驗(一節有5個練習和1個測驗)。當單擊quiz
按鈕時,我試圖使用當前的$session_id
顯示測驗題目和作者,並將其與數據庫中的quiz_list
表中的session_id
鏈接起來。用C SESSION_ID:通過php和html顯示測驗
沒有顯示的是,我得到這樣的錯誤:
注意:未定義指數\ XAMPP \ htdocs中\上線項目\ quiz.php 8
警告:mysqli_fetch_assoc ()預計參數1被mysqli_result,在C中給出布爾:\ XAMPP \ htdocs中\上線項目\ quiz.php 13
exercise.php:
<?php
//build up array as iterate through while loop
$sessions_quiz_array = array();
$get_quiz = mysqli_query($con, "SELECT * FROM `quiz_list` WHERE `session_id` = $session_id");
//fetches result row as an associative array
while ($row_quizes = mysqli_fetch_assoc($get_quiz)) {
$sessions_quiz_array[] = $row_quizes;
}
//sessions_quiz_array is the associative array being looped
foreach ($sessions_quiz_array as $key => $value) {
$quiz_id = $value['id'];
$quiz_title = $value['quiz_title'];
$quiz_author = $value['quiz_author'];
?>
<a id='button' href="quiz.php?id=<?php echo $quiz_id; ?>"> Quiz</a>
<?php } ?>
quiz.php
<?php
session_start();
include("includes/database.php");
?>
<?php
//gets current
$session_id = $_GET['session_id'];
$get_quiz = "SELECT * FROM `quiz_list` WHERE `session_id` = $session_id";
$run_quiz = mysqli_query($con, $get_quiz);
$quiz_info = mysqli_fetch_assoc($run_quiz);
?>
<hr>
<div>
<h1><?php echo $quiz_info["id"]; ?> </h1>
<br>
<p><?php echo $quiz_info["quiz_title"]; ?></p>
<br>
<p><strong><?php echo $quiz_info["quiz_author"]; ?></strong></p>
</div>
<hr>
<a href="interactive_training.php" class="button previous">« Back to Training</a>
任何幫助將不勝感激。
@FuzzyTree感謝指出了這一點!修復! – Davidaj