我有一个php脚本,用于为jeasyUI Grid生成信息。
$sql = $db->query(sprintf("SELECT ID, rec_purID, rec_qty, rec_date, p.pur_ID, p.pur_productID, p.pur_supplierID, p.pur_unitPrice, pr.prod_productName, c.cont_fullName FROM receipts inner join purchases p on rec_purID = p.pur_ID inner join products pr on p.pur_productID = pr.prod_productID inner join contacts c on p.pur_supplierID = c.cont_ID")) or SQLError();
while($rec = $sql->fetch_assoc()) {
$group[] = $rec;
}
foreach ($group as $key => $val) {
$group[$key]['rec_val'] = $val['rec_qty'] * $val['pur_unitPrice'];
}
$smarty->assign('group', $group);
如果我print_r这个数组,它似乎是正确的:
Array (
[0] => Array ( [ID] => 78 [rec_purID] => 32 [rec_qty] => 1000 [rec_date] => 2016-03-30 [pur_ID] => 32 [pur_productID] => 5 [pur_supplierID] => 41 [pur_unitPrice] => 100.00 [prod_productName] => Acetate Tow [cont_fullName] => DELPACK TRADING (PTY) LTD [rec_val] => 100000 )
[1] => Array ( [ID] => 79 [rec_purID] => 31 [rec_qty] => 2207 [rec_date] => 2016-03-30 [pur_ID] => 31 [pur_productID] => 5 [pur_supplierID] => 41 [pur_unitPrice] => 95.50 [prod_productName] => Acetate Tow [cont_fullName] => DELPACK TRADING (PTY) LTD [rec_val] => 210768.5 )
[2] => Array ( [ID] => 80 [rec_purID] => 31 [rec_qty] => 3000 [rec_date] => 2016-03-31 [pur_ID] => 31 [pur_productID] => 5 [pur_supplierID] => 41 [pur_unitPrice] => 95.50 [prod_productName] => Acetate Tow [cont_fullName] => DELPACK TRADING (PTY) LTD [rec_val] => 286500 )
)
我的网格永远不会看到“rec_val”的值。请有人解释我哪里出错了。
<table id="dg" class="easyui-datagrid" style="width:100%;height:400px"
url="receipts.php?do=list"
title="Received Goods"
toolbar="#toolbar" pagination="true"
iconCls="icon-edit" showFooter="true"
sortName="ID" sortOrder="asc"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="ID" width="10" sortable="true">Internal ID</th>
<th field="prod_productName" width="80" sortable="true">Product</th>
<th field="cont_fullName" width="80" sortable="true">Supplier</th>
<th field="rec_qty" width="80" sortable="true">Quantity</th>
<th field="pur_unitPrice" width="80">Unit Price</th>
<th field="rec_val" width="80">Value</th>
<th field="rec_date" width="80" sortable="true">Date Received</th>
</tr>
</thead>
</table>
谢谢。
答案 0 :(得分:0)
其中一个名称中似乎有括号,我认为这些括号无法正确转义。
DELPACK TRADING (PTY) LTD
这恰好在&#34; rec_val&#34;。
之前关闭了数组我不熟悉easyui,但我认为这是问题,特别是如果其他值确实正确显示。
答案 1 :(得分:0)
我最后的解决方案是在查找中执行计算:
$row = $db->query(sprintf("SELECT ID, rec_purID, rec_qty, rec_date, p.pur_ID, p.pur_productID, p.pur_supplierID, p.pur_unitPrice, CAST((rec_qty * p.pur_unitPrice) as UNSIGNED) as rec_value, pr.prod_productName, c.cont_fullName FROM receipts inner join purchases p on rec_purID = p.pur_ID inner join products pr on p.pur_productID = pr.prod_productID inner join contacts c on p.pur_supplierID = c.cont_ID")) or SQLError();
CAST((rec_qty * p.pur_unitPrice)为UNSIGNED)为rec_value