2 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊
如果您有兩個(gè)不同的數(shù)組,則無(wú)法訂購(gòu)。在您當(dāng)前的情況下,您的所有發(fā)票都會(huì)在打印付款之前打印。
因此,從某種意義上說(shuō),您必須在單個(gè) Query 中處理此問(wèn)題。您需要像這樣在單個(gè)查詢構(gòu)建中獲取所有數(shù)據(jù)(發(fā)票和付款),
$data = SomeCommonTable::leftJoin('invoice...')
->leftJoin('payment...')
->selectRaw(...)
->orderBy('date','asc/desc)
->get();
如果你不能像上面的查詢那樣實(shí)現(xiàn),你需要在兩者中unionAll使用selectRaw相同的queryBuilder,一旦你聯(lián)合它,你就可以添加orderBy('date','asc/desc')你的聯(lián)合查詢。您可以在此處參考文檔以獲取更多詳細(xì)信息union

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊
如果你想從查詢中做到這一點(diǎn),那么你必須簡(jiǎn)單地使用union all你可以在同一行中選擇 inv_date 和 transaction_date 列的地方。
在 php.ini 中還有另一種方法可以做到這一點(diǎn)。您可以使用數(shù)組方法。
用這個(gè):
$reqSalesPayments = array_merge($reqsales, $reqpayments);
$inv_date = array_column($reqsales, 'inv_date');
$transaction_date = array_column($reqpayments, 'transaction_date');
$arr = array_merge($inv_date, $transaction_date);
array_multisort($arr, SORT_ASC, $reqSalesPayments);
foreach($reqSalesPayments as $sales){
//Print the table
}
- 2 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報(bào)