我正在为我的商店创建一个页面,但我使用的是 get_result,在完成所有操作后,我意识到 HostGator 不允许我运行 mysqlnd。所以我不得不将所有内容都转换为 bind_result 但我在这里陷入了死胡同,可能是因为我必须改变一切而感到沮丧......
无论如何,我的问题是我调用了一些查询来读取表,但整个代码在返回 1 个结果后停止。例如,在这段代码中,我调用了一个约会列表,虽然我在数据库中设置了 5 个约会,但它只返回第一个。它按预期工作并从多个表中读取,但在 1 个循环处停止。如果我不做 $listappointments_stmt->free_result(); 就不会让我继续阅读第二张桌子。首先在下一个查询之前,所以我认为这是我的问题,但我不知道如何解决它,因为如果我没有它,它会给我一个布尔错误。欢迎任何想法!
提前谢谢你,Xenos K。
<?php
$query="SELECT * FROM appointments";
$listappointments_stmt=$mysqli->prepare($query);
$listappointments_stmt->execute();
$listappointments_stmt->bind_result($AppId, $AppDate, $AppTime, $AppType, $AppArtist, $AppTitle, $AppClient, $AppPrice, $AppNotes);
while ($listappointments_stmt->fetch())
{
$theDate=date("d-M-Y", strtotime($AppDate));
echo "<tr><td>".$theDate."</td>";
echo "<td>".$AppTime."</td>";
$listappointments_stmt->free_result();
$tempappointmentType=$AppType;
$query2="SELECT * FROM appointmenttypes WHERE ID=?";
$listappointmentsTypes_stmt=$mysqli->prepare($query2);
$listappointmentsTypes_stmt->bind_param("s", $tempappointmentType);
$listappointmentsTypes_stmt->execute();
$listappointmentsTypes_stmt->bind_result($AppTypeId, $AppTypeName, $AppTypeColor);
while ($listappointmentsTypes_stmt->fetch())
{
echo "<td><span class=\"label\" style=\"background-color:".$AppTypeColor."\">".$AppTypeName."</span></td>";
}
$listappointmentsTypes_stmt->free_result();
$listappointmentsTypes_stmt->close();
$tempappointmentArtist=$AppArtist;
$query3="SELECT * FROM staff WHERE ID=?";
$listappointmentsArtist_stmt=$mysqli->prepare($query3);
$listappointmentsArtist_stmt->bind_param("s", $tempappointmentArtist);
$listappointmentsArtist_stmt->execute();
$listappointmentsArtist_stmt->bind_result($ArtId, $ArtName, $ArtNickName, $ArtSurname, $ArtPhone, $ArtBirthDate, $ArtIdentificationNumber, $ArtStreetName, $ArtStreetNumber, $ArtPostalCode, $ArtCity, $ArtCountry, $ArtPosition, $ArtEmail, $ArtFacebook, $ArtInstagram);
while ($listappointmentsArtist_stmt->fetch())
{
echo "<td>".$ArtName." ".$ArtNickName." ".$ArtSurname."</td>";
}
$listappointmentsArtist_stmt->free_result();
$listappointmentsArtist_stmt->close();
echo "<td>".$AppTitle."</td>";
$tempappointmentClient=$AppClient;
$query4="SELECT * FROM clients WHERE ID=?";
$listappointmentsClient_stmt=$mysqli->prepare($query4);
$listappointmentsClient_stmt->bind_param("s", $tempappointmentClient);
$listappointmentsClient_stmt->execute();
$listappointmentsClient_stmt->bind_result($CliId, $CliName, $CliSurname, $CliPhone, $CliBirthDate, $CliIdentificationNumber, $CliStreetName, $CliStreetNumber, $CliPostalCode, $CliCity, $CliCountry, $CliFathersFullName, $CliMothersFullName, $CliEmail, $CliFacebook, $CliInstagram, $CliNotes);
while ($listappointmentsClient_stmt->fetch())
{
echo "<td>".$CliName." ".$CliSurname."</td>";
echo "<td>".$CliPhone."</td>";
}
$listappointmentsClient_stmt->free_result();
$listappointmentsClient_stmt->close();
echo "<td>".$AppPrice."</td>";
echo "<td><a href=\"appointmentsedit.php?appointmentStatus=view&appointmentId=".$AppId."\" title=\"".$lang['view']."\"><i class=\"text-green fa fa-eye\"></i></a></td>";
echo "<td><a href=\"appointmentsedit.php?appointmentStatus=edit&appointmentId=".$AppId."\" title=\"".$lang['edit']."\"><i class=\"text-blue fa fa-edit\"></i></a></td>";
echo "<td><a href=\"appointmentsedit.php?appointmentStatus=delete&appointmentId=".$AppId."\" title=\"".$lang['delete']."\"><i class=\"text-red fa fa-trash-o\"></i></a></td></tr>";
}
$listappointments_stmt->close();
?>