stdClass object 可以使用 -> 去指定key 來取值。
例如
foreach ($r as $d ) {
# code...
echo 'item ';
echo $d -> itemid ;
echo $d -> num;
}
<?php
defined('DS') OR define('DS', DIRECTORY_SEPARATOR);
defined('EXT') OR define('EXT', '.php');
defined('ENVIRONMENT') OR define('ENVIRONMENT', 'development');
$dir_path = dirname(__FILE__) . DS;
defined('BASEPATH') OR define('BASEPATH', $dir_path . 'm/system' . DS);
defined('APPPATH') OR define('APPPATH', $dir_path . 'm/application' . DS);
function getDBConnector(){
include_once(BASEPATH . "core/Common.php");
include_once(BASEPATH . "core/Exceptions.php");
require_once(BASEPATH . 'database/DB' . EXT);
$conn = & DB();
return $conn;
}
$db = getDBConnector();
/*echo $db->get('vote_table')->result_array();
print_r($db->get('vote_table')->result_array());
*/
$query = $db->select('itemid, count(itemid) AS num')
->group_by('itemid')
->order_by('num', 'desc')
->get('vote_table', 24);
$r=$query->result();
?>
Array
(
[0] => stdClass Object
(
[itemid] => 14
[num] => 1
)
)
沒有留言:
張貼留言