【发布时间】:2020-05-16 01:04:48
【问题描述】:
新输入的产品显示在最后一行。如果量大,底部很难看到。如何将新显示更改为顶部。谢谢!
$barcodes_ary = explode(',', $barcodes);
$barcodes_hash = array ();
foreach ($barcodes_ary as $b) {
if (array_key_exists($b, $barcodes_hash)) {
$barcodes_hash[$b] += 1;
} else {
$barcodes_hash[$b] = 1;
}
}
foreach ($barcodes_hash as $b => $amount) {
if ($barcodes_ary == array(''))continue;
$ary = get_sql("SELECT * FROM Products WHERE Barcode='$b' Order by ProductName");
if ( count($ary) == 0 ) {
continue;
}
$pid = $ary[0]['ProductID'];
$pn = $ary[0]['ProductName'];
$unit = $ary[0]['UnitID'];
$ary2 = get_sql("SELECT UnitName FROM Units WHERE UnitID = '$unit'");
$unit = $ary2[0]['UnitName'];
?>
<TR>
<TD><? echo "$pn"; ?></TD>
<TD>
<INPUT TYPE=hidden NAME=productid<?=$pid?> VALUE='<?=$pid?>'>
<?
$candidates = array();
for($i=1; $i <= DropDownMaxValue; $i++) {
$candidates[]=$i;
}
//更新 我用另一种方法来解决问题。只需展示相同的产品即可。
function push_barcode() {
// alert('barcode pushing');
b = document.form1.barcode;
bs = document.form1.barcodes;
if (bs.value == "") {
bs.value = b.value;
} else { // ?? 111,333,444,... ???
bs.value = b.value;
}
}
【问题讨论】:
-
为什么不直接反转数组?
-
"SELECT * FROM Products WHERE Barcode='$b' Order by ProductName DESC"DESC将从末尾开始并向后排序查询... -
@Premlatha krsort($ary);不工作
-
@dalelandry $ary = get_sql("SELECT * FROM Products WHERE Barcode='$b' Order by ProductName DESC");不工作。
标签: php arrays sorting sql-order-by