当我使用 a 执行一些查询时$this->query
,CakePHP 返回:
型号:
<?php
App::uses('AppModel', 'Model');
class Authorization extends AppModel {
public $displayField = 'name';
public $useTable = 'auth';
public $actsAs = array();
模型中的 SQL:
public function getNotUsed($initialDate, $finalDate)
{
$sql = "SELECT auth_num ,
auth_code ,
amount AS verisign_amount ,
print_amount ,
card_name ,
a.table_num AS table_num ,
a.add_date AS date ,
'Tb:'|| table_num || ' - ' || auth_code || ' - $' || print_amount AS code_print_amount
FROM auth a
WHERE trxtype = 'S'
AND gift_card = 'N'
AND used = 'N'
AND a.add_date BETWEEN '$initialDate' AND '$finalDate'
AND pnref NOT IN
(SELECT origid
FROM auth a
WHERE add_date BETWEEN '$initialDate' AND '$finalDate'
AND trxtype = 'V')
ORDER BY add_date";
return $this->query($sql);
}
Array
(
[0] => Array
(
[0] => Array
(
[auth_num] => 536825
[auth_code] => 0000000
[verisign_amount] => 0.50
[print_amount] => 0.50
[card_name] => TEST
[table_num] => 37
[date] => 02/20/2013 14:56:35
[code_print_amount] => Tb:37 - 198198 - $0.50
)
)
)
我想要这个(当搜索超过 1 行时):
Array
(
[0] => Array
(
['Authorization'] => Array
(
[auth_num] => 536825
[auth_code] => 0000000
[verisign_amount] => 0.50
[print_amount] => 0.50
[card_name] => TEST
[table_num] => 37
[date] => 02/20/2013 14:56:35
[code_print_amount] => Tb:37 - 198198 - $0.50
)
)
)
或者这个(当搜索更多 1 行时 - 限制 1):
Array
(
['Authorization'] => Array
(
[auth_num] => 536825
[auth_code] => 0000000
[verisign_amount] => 0.50
[print_amount] => 0.50
[card_name] => TEST
[table_num] => 37
[date] => 02/20/2013 14:56:35
[code_print_amount] => Tb:37 - 198198 - $0.50
)
)
如何执行此查询并仅获取第一个数组键(包含所有字段)。在这种情况下,第二个数组键 [0]。或者只是一个[0] => ['Authorization'] => array()
.
我在用着:
- CakePHP 2.3.0
- PHP 5.3.8
- 阿帕奇 2.2
- Postgres 8.4