<div class="transaction-list">
<!-- START 1ST LOOP -->
<?php
foreach($transaction_list_buy as $transaction) {
?>
<div class="transaction-item px-4 py-3" data-toggle="modal" data-target="#P<?php echo $transaction->deal_id; ?>">
<div class="row align-items-center flex-row">
<div class="col-2 col-sm-1 text-center d-none d-sm-block"> <span class="d-block text-4 font-weight-300"><?php $date=date_create($transaction->deal_datetime); echo date_format($date,"d"); ?></span> <span class="d-block text-1 font-weight-300 text-uppercase"><?php $date=date_create($transaction->deal_datetime); echo date_format($date,"M"); ?></span> </div>
<div class="col col-sm-7"> <span class="d-block text-4"><?php echo $transaction->deal_id; ?></span> <span class="text-muted">
<?php
if($transaction->deal_status==0) {
echo "Buyer Initiated";
} else if($transaction->deal_status==1) {
echo "Prepay Verified Deal";
} else if($transaction->deal_status==2) {
echo "Seller Confirmed";
} else if($transaction->deal_status==3) {
echo "Buyer Received";
} else if($transaction->deal_status==4) {
echo "Seller Claimed";
} else if($transaction->deal_status==5) {
echo "Prepay Released Payment";
} else if($transaction->deal_status==6) {
echo "Buyer Cancelled";
}else if($transaction->deal_status==7) {
echo "Prepay Dropped";
}?>
</span> </div>
<div class="col-2 col-sm-2 text-center text-3"> <span class="text-success" data-toggle="tooltip" data-original-title="Payment Verified"><i class="fas fa-check-circle"></i></span> </div>
<div class="col-3 col-sm-2 text-right text-4"> <span class="text-2 text-uppercase">RM</span> <span class="text-nowrap"><?php echo number_format($transaction->payment_amount, 2, '.', ''); ?></span> </div>
</div>
</div>
<?php
}
?>
<!-- START 2ND LOOP -->
<?php
foreach($transaction_list_sell as $transaction) {
?>
<div class="transaction-item px-4 py-3" data-toggle="modal" data-target="#P<?php echo $transaction->deal_id; ?>">
<div class="row align-items-center flex-row">
<div class="col-2 col-sm-1 text-center d-none d-sm-block"> <span class="d-block text-4 font-weight-300"><?php $date=date_create($transaction->deal_datetime); echo date_format($date,"d"); ?></span> <span class="d-block text-1 font-weight-300 text-uppercase"><?php $date=date_create($transaction->deal_datetime); echo date_format($date,"M"); ?></span> </div>
<div class="col col-sm-7"> <span class="d-block text-4"><?php echo $transaction->deal_id; ?></span> <span class="text-muted">
<?php
if($transaction->deal_status==0) {
echo "Buyer Initiated";
} else if($transaction->deal_status==1) {
echo "Prepay Verified Deal";
} else if($transaction->deal_status==2) {
echo "Seller Confirmed";
} else if($transaction->deal_status==3) {
echo "Buyer Received";
} else if($transaction->deal_status==4) {
echo "Seller Claimed";
} else if($transaction->deal_status==5) {
echo "Prepay Released Payment";
} else if($transaction->deal_status==6) {
echo "Buyer Cancelled";
}else if($transaction->deal_status==7) {
echo "Prepay Dropped";
}?>
</span> </div>
<div class="col-2 col-sm-2 text-center text-3"> <span class="text-success" data-toggle="tooltip" data-original-title="Payment Verified"><i class="fas fa-check-circle"></i></span> </div>
<div class="col-3 col-sm-2 text-right text-4"> <span class="text-2 text-uppercase">RM</span> <span class="text-nowrap"><?php echo number_format($transaction->payment_amount, 2, '.', ''); ?></span> </div>
</div>
</div>
<?php
}
?>
</div>只是相同的数据结构。不同的是买(1)和卖(2)。
根据当前代码,数据将从已完成的第一个循环中打印出来,然后再开始第二个循环。这里的问题是,两者都包含日期&,我希望合并这两者,并根据顶部的最新/最新日期对它们进行排序。
目前,循环将从最老的开始。
发布于 2019-11-22 22:04:11
在输出任何内容之前进行合并。
迭代事务列表,并使用日期时间作为键将它们的项添加到新数组中。您可能需要将$datetime转换为可排序的格式,如Y-m-d或时间戳(如果尚未转换为时间戳)。
foreach ([$transaction_list_buy, $transaction_list_sell] as $list) {
foreach ($list as $transaction) {
$datetime = $transaction->deal_datetime;
// reformat $datetime if it is not sortable
$merged[$datetime][] = $transaction; // append rather than assign
}
}每个日期时间都应该包含一个事务数组。如果我们将单个值设置为$merged[$datetime] = $transaction;而不是$merged[$datetime][] = $transaction;,那么如果某些事务具有相同的日期时间值,则可能会覆盖值。
然后您可以按键进行排序并输出排序列表:
krsort($merged);
foreach ($merged as $datetime => $transactions) {
foreach ($transactions as $transaction) {
// output transaction
}
}与合并/排序无关,但可以考虑将状态字符串存储在数组中。那你就可以
echo $status_string[$transaction->deal_status];而不是其他的假设。
发布于 2019-11-26 18:01:28
没事的。找到了最简单的方法。只需查询买或卖。然后按日期排序
https://stackoverflow.com/questions/59001749
复制相似问题