我爲我的商店創建了一個頁面,但是我使用了get_result,並且在完成了所有操作後,我意識到HostGator不允許我運行mysqlnd。所以我不得不將所有東西都轉換爲bind_result,不過我現在處於死衚衕,可能是因爲我不得不改變一切而感到沮喪......用bind_result返回超過1個mysql條目
無論如何,我的問題是我調用一些查詢來讀取表,但整個代碼在返回1個結果後停止。例如,在這段代碼中,我要求一個約會列表,儘管我在數據庫中設置了5個約會,但它只返回第一個約會。它的工作原理是從多個表中讀取,但是在1個循環處停止。如果我沒有執行$ listappointments_stmt-> free_result(),它不會讓我繼續閱讀第2個表。 首先在下一個查詢之前,所以我認爲這是我的問題,但我不知道如何工作,因爲它給了我一個布爾錯誤,如果我沒有它。任何想法歡迎!
謝謝你在前進, 的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();
?>
非常感謝您的信息Ollie。建立一個額外的連接,並移動free_result的伎倆。我會改變最終產品上的Select *,並會像你剛纔提到的那樣進入JOIN。再次感謝你! –