我有2個表名每個名稱shipping_infos和訂單。我想從兩張表中獲得多列。這兩個表共享一個相同的列,即user_id列。我一直在嘗試這個代碼,但它仍然返回null。我應該如何寫它?如何從sql數據庫中的2個表的多個列中獲取數據?
<?php
include ('classes/functions.php');
if(isset($_POST['user_id'])){
$user_id = $_POST['user_id'];
$check_receipt = "select
shipping_infos.shipping_name,shipping_infos.shipping_address,
shipping_infos.shipping_contact,shipping_infos.shipping_email,
orders.order_date,orders.trx_id,orders.tracking_num from
shipping_infos inner join orders on shipping_infos.user_id = orders.user_id
where user_id= '".$user_id."';";
$run_receipt_checking = mysqli_query($con, $check_receipt);
$result = array();
while($row = mysqli_fetch_array($run_receipt_checking)){
array_push($result,
array(
'shipping_name'=>$row[2],
'shipping_address'=>$row[3],
'shipping_contact'=>$row[4],
'shipping_email'=>$row[5],
'order_date'=>$row[8],
'trx_id'=>$row[1],
'tracking_num'=>$row[2],
));
}
echo json_encode(array("result"=>$result));
} ?>
gofr1打我的一拳,現在我只是要補充一點,這個代碼是可行的SQL注入。由於您已經使用mysqli,[學習如何綁定值](http://php.net/manual/en/mysqli-stmt.bind-param.php)。 – Xorifelse