大家好,我需要以下帮助代码,
我正在尝试使用 json 将 2 个不同的结果从 mysql php 提取到 ajax。
这是我目前所拥有的。
我可以提取 1 个包含信息的表格,但不知道如何提取 2 个不同的结果。请帮我。
PHP 文件
$id = $_POST["order"];
$order = mysql_query("SELECT * FROM `orders` WHERE `order_id` = {$id} ORDER BY id DESC");
$test_quote = mysql_query("
SELECT paid
FROM `outstanding`
WHERE order_id = {$id}
");
$array = array();
//pulling outstanding if product paid or not
if(mysql_num_rows($test_quote) > 0 ){
$array[] = mysql_fetch_array($test_quote);
}
//pulling products
if (mysql_num_rows($order) > 0){
while($row = mysql_fetch_array($order)){
$array[] = $row;
}
} else { echo "<div style='font-size:12px;'>No orders yet</div>";}
echo json_encode($array);
它拉 1 个查询,但无法从 php 文件中获取另一个查询
jQuery
$.ajax({
type: "POST",
url: "order_load.php",
data: {order : thisId},
dataType:"json",
success: function(data){
$.each(data, function(i, val){
var append2 = '<div class="product">';
append2 +='<div class="view_left2">';
append2 +='<b>Item ID:</b> ';
append2 +='#'+val.id;
append2 +='</div>';
append2 +='<div class="line"><img src="images/productLine.png" /></div>';
append2 +='<div class="viewleft3">'+val.desc+'</div>';
append2 +='<div class="right_order">';
append2 +='<div class="line"><img src="images/productLine.png" /></div>';
append2 +='<div class="view_right2">';
append2 +='<div class="price3">$'+val.amount+'</div></div><div class="clear"></div></div>';
append2 +='<div class="clear"></div></div>';
$(".view_product2").append(append2);
});
这是我的 json 输出:
[{"0":"1","paid":"1"},{"0":"336","id":"336","1":"1","qty":"1","2":"sdfgsdf","desc":"sdfgsdf","3":"yes","gst":"yes","4":"44","price":"44","5":"44.00","amount":"44.00","6":"225","order_id":"225"}]