以下是开始的代码:
*<?php
$sql_query = "SELECT * FROM DistributorCourses WHERE Distributor = '". $Distributor ."'";
$result = mysqli_query($dbconfig, $sql_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
echo '<div class="row">';
echo '<div class="col-md-12">';
echo '<table class="table">';
if($count > 1) {
echo '<tr>';
echo '<th>Course Title</th> ';
echo '<th>Price</th>';
echo '<th>Purchase</th>';
echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['Title'] .'</td> ';
echo '<td>'. $row['Price'] .'</td> ';
if ($row['Title'] == $course && in_array("". $row['Title'] ."", $descriptions)) {
echo '<td><a href="#" title="Retake Exam" class="btn btn-warning">Retake Exam</a></td>';
}
elseif (in_array("". $row['Title'] ."", $descriptions)) {
echo '<td><a href="#" title="You have already purchased this course!" class="btn btn-default" style="background: #e6e6e6; border: 1px solid #adadad; cursor: default;">You have already purchased this course!</a></td>';
}
else {
echo '<td><a href="purchase.php?courseid='. $row['CourseID'] .'&title='. $row['Title'] .'" title="" class="btn btn-success">Purchase Course</a></td>';
}
echo '</tr>';
}
}
echo '</table>';
echo '</div>';
echo '</div>';
?>*
这段代码非常出色但是......第一个elseif
语句不起作用,我不明白为什么。任何人都可以找出原因吗?
我有一个$descriptions
的数组,如果课程标题($row['Title'])
在$descriptions
中,我希望这样做,以显示&#34;重新考试&#34;如图所示。目前它仍然说“你已经购买了这门课程!”#。#。
$sql_query = "SELECT * FROM CustomisePage WHERE Distributor = '$Distributor'";
$result = mysqli_query($dbconfig, $sql_query);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1) {
$Image = $row['Image'];
$ImageAlt = $row['ImageAlt'];
$headercolour = $row['headercolour'];
$footercolour = $row['footercolour'];
}
$sql_query1 = "SELECT order_description FROM single_user_orders WHERE username = '". $_SESSION['login_user'] ."'";
$result1 = mysqli_query($dbconfig, $sql_query1);
$count1 = mysqli_num_rows($result1);
if($count1 >= 1) {
while ($row1 = $result1->fetch_assoc()) {
$descriptions[] = $row1['order_description'];
}
}
$sql_query2 = "SELECT pass_or_fail, course FROM single_user_exam_results WHERE user_on_course = '". $_SESSION['login_user'] ."'";
$result2 = mysqli_query($dbconfig, $sql_query2);
$count2 = mysqli_num_rows($result2);
if($count2 >= 1) {
while ($row2 = $result2->fetch_assoc()) {
$passfail[] = $row2['pass_or_fail'];
$course[] = $row2['course'];
}
}
答案 0 :(得分:0)
如果我看到这个,你说$ course是一个数组。就像你之后做的一样,这样做。
自:
if ($row['Title'] == $course && in_array("". $row['Title'] ."", $descriptions)) {
要:
if (in_array($row['Title'], $course) && in_array($row['Title'], $descriptions)) {
那可以做到。