Php MySQL查询有2个数组,但其中1个不显示结果
我有下面的代码Php MySQL查询有2个数组,但其中1个不显示结果,php,mysql,Php,Mysql,我有下面的代码 <?php mysql_connect("x", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxxx") or die(mysql_error()); $query = "select sp1.sale_id idsale, round((sik1.quantity_purchased*sik1.item_unit_price)+((IFNULL(0,sit1.percent)/100)*(sik1.q
<?php
mysql_connect("x", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxxx") or die(mysql_error());
$query = "select sp1.sale_id idsale,
round((sik1.quantity_purchased*sik1.item_unit_price)+((IFNULL(0,sit1.percent)/100)*(sik1.quantity_purchased*sik1.item_unit_price))-
((sik1.discount_percent/100)*(sik1.quantity_purchased*sik1.item_unit_price))) as total,
round(sum(sp1.payment_amount)) as paid, DATE_FORMAT(now(),'%Y-%m-%d') as now,
DATE_FORMAT(DATE_ADD(max(sp1.payment_date),INTERVAL 20 DAY),'%Y-%m-%d') as 'duedate',
if ((round((sik1.quantity_purchased*sik1.item_unit_price)+((IFNULL(0,sit1.percent)/100)*(sik1.quantity_purchased*sik1.item_unit_price))-
((sik1.discount_percent/100)*(sik1.quantity_purchased*sik1.item_unit_price))))>(round(sum(sp1.payment_amount))),0,1) as lunas,
if ((DATEDIFF(DATE_FORMAT(DATE_ADD(max(sp1.payment_date),INTERVAL 10 DAY),'%Y-%m-%d'),DATE_FORMAT(now(),'%Y-%m-%d')))<0,0,1) due
from sales_payments sp1
left join sales_items sik1 on (sik1.sale_id=sp1.sale_id)
left join sales_items_taxes sit1 on
(sit1.sale_id=sp1.sale_id)
where sik1.quantity_purchased IS NOT NULL
group by sp1.sale_id
union
select sp2.sale_id idsale,
round((sik2.quantity_purchased*sik2.item_kit_unit_price)+((IFNULL(0,sit2.percent)/100)*(sik2.quantity_purchased*sik2.item_kit_unit_price))-
((sik2.discount_percent/100)*(sik2.quantity_purchased*sik2.item_kit_unit_price))) as total,
round(sum(sp2.payment_amount)) as paid, DATE_FORMAT(now(),'%Y-%m-%d') as now,
DATE_FORMAT(DATE_ADD(max(sp2.payment_date),INTERVAL 20 DAY),'%Y-%m-%d') as 'duedate',
if ((round((sik2.quantity_purchased*sik2.item_kit_unit_price)+((IFNULL(0,sit2.percent)/100)*(sik2.quantity_purchased*sik2.item_kit_unit_price))-
((sik2.discount_percent/100)*(sik2.quantity_purchased*sik2.item_kit_unit_price))))>(round(sum(sp2.payment_amount))),0,1) as lunas,
if ((DATEDIFF(DATE_FORMAT(DATE_ADD(max(sp2.payment_date),INTERVAL 10 DAY),'%Y-%m-%d'),DATE_FORMAT(now(),'%Y-%m-%d')))<0,0,1) due
from sales_payments sp2
left join sales_item_kits sik2 on (sik2.sale_id=sp2.sale_id)
left join sales_item_kits_taxes sit2 on
(sit2.sale_id=sp2.sale_id)
where sik2.quantity_purchased IS NOT NULL
group by sp2.sale_id";
/*
The result of query is
"payment_id";"sale_id";"payment_type";"payment_amount";"truncated_card";"card_issuer";"payment_date"
"84";"49";"Tunai";"150000.0000000000";;;"2015-01-11 00:01:40"
"85";"52";"Tunai";"150000.0000000000";"0";;"2015-01-11 00:18:41"
"87";"53";"Tunai";"750000.0000000000";"0";;"2015-01-11 00:24:53"
"102";"50";"Tunai";"75000.0000000000";"0";;"2014-12-16 22:45:12"
"104";"54";"Tunai";"20000.0000000000";"0";;"2015-01-12 02:36:19"
"105";"51";"Tunai";"135000.0000000000";"0";;"2015-01-13 03:04:49"
*/
$result = mysql_query($query) or die ("no query");
$result_array = array();
while($ngebon = mysql_fetch_assoc($result))
{
if ($ngebon['total'] > $ngebon['paid']) {
$result_array[] = $ngebon['idsale'];
echo $ngebon['idsale']." ".$ngebon['due']."<br>"; //result is idsale 50 and 51
}
}
$result2 = mysql_query($query) or die ("no query");
$result_array_due = array();
while($ngebon2 = mysql_fetch_assoc($result2))
{
if ($ngebon2['due'] = 0) {
$result_array_due[] = $ngebon2['idsale'];
echo $ngebon2['idsale']." ".$ngebon2['due']."<br>"; //no result
}
}
?>
但是我所做的一切对于$ngebon2没有结果,而$ngebon显示正确。事实上,在phpmyadmin中执行的查询显示有1个结果
of$ngebon2['idsale'] where $ngebon2['due'] = 0 .
您可以检查上面的查询结果
有人能帮忙吗?如果你的问题只涉及mysql,那么请删除所有无Sql代码,这很难理解。嗨,贝里,谢谢你的建议,但无Sql代码是什么意思?因为数组代码似乎很重要,需要知道……对不起,我们的标签误导了我——根据您的评论,您的查询会返回结果,所以请将PHP标签添加到您的问题中。问题一定在那里,好的,谢谢你在我的问题中添加了PHP标签。。
of$ngebon2['idsale'] where $ngebon2['due'] = 0 .