您看到的代碼來自生成下拉列表的應用程序。您從下拉列表中進行選擇並生成報告。我正在將這個應用程序從舊版本的php遷移到最新版本,但是我無法獲得在表單上生成的列表。任何人都可以告訴我我做錯了什麼或需要改變什麼。我不是PHP開發人員,我正在學習,但我還沒有。從PHP4移植到PHP5
function getcourses(){
$query = "SELECT DISTINCT * FROM courses";
$result = mysqli_query($dbc,$query);
while($row = mysql_fetch_array($result)){
$course_id = $row['course_id'];
$course_no = $row['course_no'];
$course_name = $row['course_name'];
$start_month = $row['start_month'];
$start_day = $row['start_day'];
$start_year = $row['start_year'];
$end_month = $row['end_month'];
$end_day = $row['end_day'];
$end_year = $row['end_year'];
$course_date = $start_month . " " . $start_day . ", " . $start_year . " - " . $end_month . " " . $end_day . ", " . $end_year;
echo '<option value="' . $course_id . '~' . $course_date . '">' . $course_name . ', ' . $course_date . '</option>';
}
}
?>
<p>Please select the course roster you would like to download from the list below</p>
<form action="download_excel.php" name="reportrequest" method="POST">
<select name="course_report">
<?php getcourses() ?>
</select>
<input class="btn btn-primary" type="submit" name="submit" id="submit" value="Retrieve Report" />
</form>
因此,這裏是新的代碼是什麼樣子,我仍然不斷收到此錯誤: PHP的警告:mysqli_fetch_array()預計參數1被mysqli_result,在
發生這種情況給定的boolean上THI行:而($行= mysqli_fetch_array($結果))
function connect(){
$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD);
return $dbc;
}
function getcourses(){
$query = "SELECT FROM courses";
$result = mysqli_query(connect(),$query);
while($row = mysqli_fetch_array($result)){
$course_id = $row['course_id'];
$course_no = $row['course_no'];
$course_name = $row['course_name'];
$start_month = $row['start_month'];
$start_day = $row['start_day'];
$start_year = $row['start_year'];
$end_month = $row['end_month'];
$end_day = $row['end_day'];
$end_year = $row['end_year'];
$course_date = $start_month . " " . $start_day . ", " . $start_year . " - " . $end_month . " " . $end_day . ", " . $end_year;
echo '<option value="' . $course_id . '~' . $course_date . '">' . $course_name . ', ' . $course_date . '</option>';
}
}
你得到什麼錯誤? –
您不能混用並匹配mysql_ *和mysqli_ *函數。 –
這是我得到的錯誤之一:mysqli_query()期望參數1是mysqli,null給出。還一直說$ dbc是一個未定義的變量。 – Campos39