我有一個PHP
錯誤,我似乎無法使用此代碼問題與PHP一樣查詢
$_POST['location'] = 'Northern Province';
$_POST['transport'] = 'transport';
if (isset($_POST['location'])) {
$region = "%{$_POST['region']}%";
$transport = "%{$_POST['transport']}%";
$stmt = $conn->prepare("SELECT users.id, users.email, users.profilePhoto, users.userType, organization.userFk, organization.name, organization.specialization from users, organization WHERE users.id = organization.userFk AND organization.specialization LIKE ? AND users.region LIKE ?");
$stmt->bind_param("ss", $transport, $regions);
$stmt->execute();
$response["transPortCompanies"] = array();
$stmt->bind_result($id, $email, $profilePhoto, $userType, $userFk, $name, $specialization);
while($row = $stmt->fetch()) {
$company = array();
$company["id"] = $id;
$company["email"] = $email;
$company["profilePhoto"] = $profilePhoto;
$company["name"] = $name;
$company["specialization"] = $specialization;
$response["message"] = "Loaded";
$response["error"] = FALSE;
array_push($response["transPortCompanies"], $company);
}
echo json_encode($response);
顯然,它返回一個空companies
列表來解決,但是當我硬編碼像
SELECT users.id, users.email, users.profilePhoto, users.userType, organization.userFk, organization.name, organization.specialization from users, organization WHERE users.id = organization.userFk AND organization.specialization LIKE '%transport%' AND users.region LIKE '%Northern Province%'
我得到我的輸出,所以想知道我哪裏錯了?我還有一個腳本,做搜索,那就是我是如何實現它
我有我的問題。如果這兩個表之間沒有**關係**,爲什麼不使用加入他們? – Karthi
@Karthi我打算這樣做,但現在我希望查詢能夠正常工作,如果是這樣的話,我打算用加入來替換它 –
使用了錯誤報告http://php.net/manual/en/function。 error-reporting.php可能會避免這個問題。 –