我有以下代码:
<?php
include_once '../includes/db.inc.php';
$sql = "SELECT * FROM clients ORDER BY nif_id ASC;";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$first = $row["prm_nome"];
$last = $row["apelido"];
$phone = $row['nmr_tlm'];
$email = $row['mail'];
$nif = $row['nif_id'];
$flight = "SELECT flight_id FROM flights INNER JOIN clients ON flights.nif_id=clients.nif_id";
echo '<tr>';
echo '<td><a href="detail.php?id='. $nif . '">'.$nif.'</a></td>';
echo '<td>'.$first.'</td>';
echo '<td>'.$last.'</td>';
echo '<td>'.$phone.'</td>';
echo '<td>'.$email.'</td>';
echo '<td><a href="../flights/detail.php?id='. $flight . '">'.$flight.'</a></td>';
echo '</tr>';
}
}
?>
我需要回显SELECT flight_id FROM flights INNER JOIN clients ON flights.nif_id=clients.nif_id
查询的结果。但是当我保存文件时,页面上显示的是该查询的链接,而不是结果。
是否应该使用第一个$sql =
下的查询来开始新的$sql =
?
还是有其他方法?
我尝试了UNION
和SELECT *, flight_id FROM flights INNER JOIN clients ON flights.nif_id=clients.nif_id FROM clients ORDER BY nif_id ASC;
,但后来得到了mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given
。
答案 0 :(得分:0)
您不需要两个查询。只需使用加入的查询即可。
class SubjectDetailView(generic.DetailView, SingleObjectMixin):
model = Programmesearch
template_name = 'mnsdirectory/subject_detail.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# subjectslug = self.object.slug # Not necessary since It's a DetailView
studyLevel = StudyLevel.objects.filter(
study_level=self.kwargs.get('studylevel', None))