How do I get these two select in a query?
//Retorna todos os dados do fornecedor
SELECT * FROM suppliers WHERE id=$id
//Retorna todos os serviços do fornecedor
SELECT suppliers_services.*, third_party_services.* FROM suppliers_services left JOIN third_party_services ON suppliers_services.id = third_party_services.id where suppliers_services.supplier_id = $id
I use an ajax to call .php and display in a modal .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 {
}
}
});
});