【发布时间】:2018-01-26 18:43:58
【问题描述】:
我需要一些关于在 SQL 或 php 中选择 MySQL 的帮助。 我的情况: 我有一个这样的sql表
ID | organization_ID | Investment | investment_curr | paid | paid_curr | effective_from | Effective_to
1 | 195001 | 5000 | EUR | NULL | EUR | 2010-06-23 | NULL
2 | 195001 | NULL | EUR | 5000 | EUR | 2010-06-23 | NULL
3 | 195001 | 2000 | SKK | NULL | SKK | 2007-08-01 | 2010-06-22
4 | 195001 | NULL | SKK | 2000 | SKK | 2007-08-01 | 2010-06-22
现在我有 php select (joomla),当按组织 ID 选择值时
$query_rpo_organization_equity_entries = $db->getQuery(true);
$query_rpo_organization_equity_entries
->select(array('organization_id',
'investment_amount',
'investment_currency',
'paid_amount',
'paid_currency',
'effective_from',
'effective_to'
))
->from($db->quoteName('rpo_organization_equity_entries'))
->where($db->quoteName('organization_id') . ' = '. $db->quote($rpo_id))
->order(($db->quoteName('effective_to') . ' IS NOT NULL'), $db->quoteName('effective_to') . ' DESC ');
$db->setQuery($query_rpo_organization_equity_entries);
$query_rpo_organization_equity_entries = $db->loadObjectList();
然后我调用foreach
foreach($query_rpo_organization_equity_entries as $rpo_organization_equity_entries) {}
一切正常,但不是我需要的方式。这foreach 返回 4 个数组,但我需要按列“effective_from”和“effective_to”合并/组合行(如果它们具有相同的值。当然还有组织 ID)。
因此,我将 ID 为 1 和 2 的行以及 ID 为 3 和 4 的行组合在一起,而不是 4 个数组,我只有 2 个像这样的组合/合并数组
XY | 195001 | 5000 | EUR | 5000 | EUR | 2010-06-23 | NULL
XY | 195001 | 2000 | SKK | 2000 | SKK | 2007-08-01 | 2010-06-22
我应该怎么做?还是先解决sql再php更好?
谢谢
【问题讨论】:
标签: php mysql arrays select joomla