我想將 PHP 產生的按鈕的 id 值從 theory.php
檔案傳遞到 theory1.php
檔案。
程式碼如下:
//theory.php file require('components/db.php'); $query = "SELECT * FROM `courses`"; $result = mysqli_query($connect, $query) or die("Error:" . mysqli_error($connect));; $numrows = mysqli_num_rows($result); for ($i = 0; $i < $numrows; $i++) { $query = "SELECT * FROM `courses` WHERE courseID = '$i'"; $result = mysqli_query($connect, $query) or die("Error:" . mysqli_error($connect));; $rowQuery = mysqli_fetch_assoc($result); $_SESSION['course_ID'] = $i; echo ' <div class="card"> <img class = "cardImage" src="'; echo $rowQuery['imageLink']; echo '" alt="Course 1"> <h3>'; echo $rowQuery['courseName']; echo '</h3> <p>'; echo $rowQuery['courseTextOne']; echo '</p> <a href="theory1.php?course_ID=$i" class="button">Proceed</a> </div>'; //a - is a button which needs to have an ID to pass to theory1.php }
該程式碼產生帶有按鈕的卡片。我希望每個按鈕都儲存 MySQL 資料庫中課程的相應 ID。該 ID 需要根據單擊的按鈕(卡)傳遞到另一個頁面,以便將來可以從資料庫中檢索正確的資料。
解決方案
理論.php:
#theory1.php: