gpt4 book ai didi

php - Mysqli 多查询或更好的替代方案

转载 作者:行者123 更新时间:2023-11-29 11:59:12 25 4
gpt4 key购买 nike

我有一个预约数据库,我可以成功打印数据。我现在要做的是将显示的约会限制为查询 1 的结果。

我当前收到两个错误,第一个错误是意外查询,另一个错误是 fatal error :函数名称必须是字符串。我将如何重写它以便两个查询都能工作?或另一种更好的方法来使其正常工作

    <?php
//MySqli Databse Connection
require "id.php";
require "calendarconnect.php";

//MySqli Select Query 1
$lep = $mysqli->query("SELECT lep FROM appointments WHERE ID = $contactid");
$line = mysqli_fetch_array($query1, MYSQL_ASSOC);

//MySqli Select Query 2
$query = $mysqli->query("SELECT ID, appointment, nature, doctorname, lep FROM appointments WHERE lep = $line ORDER BY appointment");

print '<table cellpadding="10" cellspacing="3" border="1" class="sortable">';
print '<tr><th>Date/Time</th><th>Nature</th><th>Doctor Name</th><th>Actions</th></tr>';
while($row = $query->fetch_assoc()) {
print '<tr>';
print "<td>" . date('m-d-y g:i A', strtotime($row['appointment'])) . "</td>";
print '<td>'.$row["nature"].'</td>';
print '<td>'.$row["doctorname"].'</td>';
print "<td><a href=\"edit.php&cd=" . $row['ID'] . "\">Edit&nbsp;|&nbsp;</a>";
print "<a href=\"appointmentdelete.php?id=" . $row['ID'] . "\"onclick=
\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";
print '</tr>';
}
print '</table>';

require "freeclose.php";
?>

最佳答案

没必要用 2 个查询来完成。因此,您不必将查询 1 的结果传输到客户端以放入第二个查询中。

试试这个:

  SELECT b.ID, b.appointment, b.nature, b.doctorname, b.lep  
FROM appointments a
LEFT JOIN appointments b ON b.lep = a.lep
WHERE a.ID = $contactid
ORDER BY b.appointment;

关于php - Mysqli 多查询或更好的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32658810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com