在我的代碼中,我有機會使用第一個SQL而不是第一個?
有人可以幫我嗎?我有什麼機會在我的代碼中使用第一個SQL,而不是第一個?
//return supplies
SELECT * FROM suppliers WHERE id=$id
//return all suppliers itens
SELECT
suppliers.*,
third_party_services.name as servicename
FROM
suppliers
INNER JOIN
suppliers_services
ON
suppliers.id = suppliers_services.supplier_id
LEFT JOIN
third_party_services
ON
suppliers_services.id = third_party_services.id
WHERE
suppliers_services.supplier_id = $id
我使用ajax的所有數據顯示成一個模式
阿賈克斯點這個.PHP
if(!empty($_POST)){
if (isset($_POST['id']) && $_POST['id'] > 0){
$id=$_POST['id'];
GetSuppliersView();
}
}
function GetSuppliersView() {
global $db;
global $id;
try{
$query = $db->query("SELECT * FROM suppliers WHERE id=$id");
$row=$query->fetch(PDO::FETCH_ASSOC);
$result['success'] = true;
$result['result'] = $row;
echo json_encode($result);
return true;
} catch (PDOException $pe) {
return false;
}
}
,這是Ajax代碼
$('.itemview').click(function (e) {
e.preventDefault();
$("#viewname").empty();
$("#viewsuppliersocialname").val("");
$("#viewsupplierfantasyname").val("");
$("#viewsuppliercnpj").val("");
$("#viewsuppliercontact").val("");
$("#viewsupplieraddress").val("");
$("#viewsupplierphone1").val("");
$("#viewsupplierphone2").val("");
$("#viewsupplierphone3").val("");
$("#viewsupplieremail1").val("");
$("#viewsupplieremail2").val("");
$("#viewpaymentmethods").val("");
var uid = $(this).data('id');
$.ajax({
type: "POST",
url: "resources/controllers/get.php",
data: 'id='+uid,
dataType: "json",
success: function (data) {
if (data.success) {
$('#viewname').append(data.result.name);
$('#viewsuppliersocialname').val(data.result.social_name);
$('#viewsupplierfantasyname').val(data.result.fantasy_name);
$('#viewsuppliercnpj').val(data.result.cnpj);
$('#viewsuppliercontact').val(data.result.contact);
$('#viewsupplieraddress').val(data.result.address);
$('#viewsupplierphone1').val(data.result.phone1);
$('#viewsupplierphone2').val(data.result.phone2);
$('#viewsupplierphone3').val(data.result.phone3);
$('#viewsupplieremail1').val(data.result.email1);
$('#viewsupplieremail2').val(data.result.email2);
$("#viewpaymentmethods").val(data.result.paymenttype).change();
$("#MethodView").modal('show');
} else {
}
}
});
});
有人可以幫我做這個嗎?
有什麼用'JOIN'問題? – Ravi