php - MySQL query result in query order -
i trying execute query contains if , case statements in select clause, , result getting grouped, each row contains element index 0 array , contains fields without if/case , ones if/case in associative array table name key... using cakephp model's query method.
here part of query
select date_format(timestampadd(hour, 4, request.creation_time), '%e-%m-%y %h:%i:%s') 'request date received', request.request_uuid 'customer id', contact_information.person_name 'customer name', service_type.id 'service_types', service.id 'lead_types', ifnull(user.username, 'n/a') 'internal owner of lead', request.request_status 'status_types', ifnull(date_format(timestampadd(hour, 4, request_activity.creation_time), '%e-%m-%y'), 'n/a') 'date of last status', ifnull(request_activity.comment, 'n/a') comment_on_status_internal
and result looks this
2014-03-10 16:57:32 debug: array ( [0] => array ( [0] => array ( [request date received] => 10-02-2014 01:49:02 [internal owner of lead] => rea [date of last status] => 10-02-2014 [time of last status] => 18:39:56 ) [request] => array ( [customer id] => 20140210000001dr [status_types] => 10 ) [contact_information] => array ( [customer name] => jihane ) [service_type] => array ( [service_types] => move ) ) [1] => array ....
and want result this
2014-03-10 16:57:32 debug: array ( [0] => array ( [request date received] => 10-02-2014 01:49:02 [customer id] => 20140210000001dr [customer name] => jihane [service_types] => move [internal owner of lead] => rea [date of last status] => 10-02-2014 [time of last status] => 18:39:56 [status_types] => 10 ) [1] => array ...
i have tried queries without case statements, looks if add if/case doesn't work. idea why?
cakephp's model query method returns associative array default. indexed return values interesting. there may cakephp method return different array. can research if like. in meantime, here's way flatten array. assumes array stored in variable $results:
foreach ($results $rkey => $rvalue) {//0 => array, 1 => array foreach ($rvalue $key => $value) {//0, request, contact_information... foreach ($value $k => $v) { //move element first sub-array slot $results[$rkey][$k] = $v; //unset associative element in sub-array unset($results[$rkey][$key][$k]); } //unset associative element in array unset($results[$rkey][$key]); } }
Comments
Post a Comment