select得到的数据集怎么遍历出来啊?

浏览:6073 发布日期:2016/11/23 分类:ThinkPHP5专区
http://www.thinkphp.cn/topic/43960.html 终结了。        $result = $this->toy_model->field('name','price')->select();
        return dump($result);
/*
        echo '<table>';
        echo '<tr>';
        echo '<td>'.'名字'.'</td>';
        echo '<td>'.'价格'.'</td>';
        echo '</tr>';
        foreach($result as $value){
            echo '<tr>';
            echo '<td>'.$value->data['name'].'</td>';
            echo '<td>'.$value->data['price'].'</td>';
            echo '</tr>';
        }
        echo '</table>';*/
    }
//dump后的结果
array(6) {
  [0] => object(app\index\model\Toy)#15 (28) {
    ["connection":protected] => array(5) {
      ["type"] => string(5) "mysql"
      ["hostname"] => string(9) "127.0.0.1"
      ["database"] => string(6) "tptest"
      ["username"] => string(4) "root"
      ["password"] => string(8) "12345678"
    }
    ["auto":protected] => array(2) {
      [0] => string(4) "name"
      [1] => string(7) "brthday"
    }
    ["query":protected] => NULL
    ["name":protected] => string(3) "Toy"
    ["table":protected] => NULL
    ["class":protected] => string(19) "app\index\model\Toy"
    ["error":protected] => NULL
    ["validate":protected] => NULL
    ["pk":protected] => NULL
    ["field":protected] => array(0) {
    }
    ["readonly":protected] => array(0) {
    }
    ["visible":protected] => array(0) {
    }
    ["hidden":protected] => array(0) {
    }
    ["append":protected] => array(0) {
    }
    ["data":protected] => array(5) {
      ["id"] => int(1)
      ["price"] => string(5) "99.99"
      ["brthday"] => string(19) "0000-00-00 00:00:00"
      ["age"] => NULL
      ["last_play_time"] => NULL
    }
data属性是protected的。
最佳答案
评论( 相关
后面还有条评论,点击查看>>