无法检索结果数据

时间:2015-04-15 12:19:49

标签: php codeigniter

我正在尝试通过查询检索一组行。但是,当我尝试检索$query->result()时,我无法检索结果集。

使用print_r($query),我得到以下结果:

object(CI_DB_mysql_result)#22 (8) {
  ["conn_id"]=> resource(61) of type (mysql link persistent) 
  ["result_id"]=> resource(82) of type (mysql result)
  ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } 
  ["custom_result_object"]=> array(0) { }
  ["current_row"]=> int(0)
  ["num_rows"]=> int(8)
  ["row_data"]=> NULL
}

该表包含数据,不为空。所有参数和名称都在代码中正确指定。

我的代码如下:

型号:

 function site_detail( $vendor_id, $city, $restict_year, $type, $total_length, $adult, $children,$pets ) {

            $this->db->select('*');
            $this->db->from('vendor_details');

            $this->db->join('vendor_siteinfo', 'vendor_siteinfo.vendor_id = vendor_details.id', 'left');
            $this->db->join('vendorstay_details', 'vendorstay_details.vendor_id=vendor_details.id');

            $this->db->where('city',$city);
            $this->db->where('year_restrict',$restict_year);
            $this->db->where('site_type',$type);
            $this->db->where('site_length',$total_length);
            $this->db->where('adult_limit',$adult);
            $this->db->where('child_limit',$children);
            $this->db->where('pet_limit',$pets);


            $query = $this->db->get(); 
            $total=$query->num_rows();
            if($total != 0)
            {
               // echo "Search details found !!!";
              //  echo "TOTAL"; echo "$total";
                return $query->result_array();
            }
            elseif($total= 0)
            {    
                //echo "No results!";
                 return false;
            }
            print_r($query);
        }

控制器:

 function search_detail($vendor_id, $city, $restict_year, $type, $total_length, $adult, $children, $pets) {

         $data['site']=$this->Home_Model->site_detail($vendor_id,$city,$restict_year,$type,$total_length,$adult,$children,$pets);
       //   $data['site_detail']=$this->Home_Model->sample($vendor_id);
         //echo "site=$site";
            print_r($data);
            $this->load->view("search_detail",$data);

    }

查看:

  <?php
     $city=$info->city;
     $restict_year=$info->year_restrict;
     $type=$info->site_type;
     $total_length=$info->site_length;
     $adult=$info->adult_limit;
     $children=$info->child_limit;
     $pets=$info->pet_limit;
     $vendor_id=$info->vendor_id;

     $site_count= $this->Home_Model->
                         get_site_count($vendor_id, $city, $restict_year, $type, $total_length, $adult, $children, $pets); 

    ?>

    <h2 class="park_name"> <a href="<?php echo base_url(); ?>index.php/home   /search_detail/<?php echo "$vendor_id"; ?>/<?php echo "$city"; ?>/<?php echo "$restict_year"; ?>/<?php echo "$type" ?>/<?php echo "$total_length"; ?>/<?php echo "$adult"; ?>/<?php echo "$children"; ?>/<?php echo "$pets"; ?>" target="_blank"><?php echo $info->name;  ?></a></h2>

2 个答案:

答案 0 :(得分:0)

检索您需要执行此操作的$query

// for object
foreach($query->result() as $row)
{
    echo $row->your_table_field_name;
}

// for array
foreach($query->result_array() as $row)
{
    echo $row['your_table_field_name'];
}

答案 1 :(得分:0)

我有同样的问题和你的建议

$result = $this->db->get()->result_array();

为我工作。 但我很好奇为什么我的原始代码突然停止工作,所有改变都是我的服务器。

$this->db->select('*');
$this->db->from('isl_user');
$this->db->order_by('isl_user.name','asc');
$query = $this->db->get();
return $query;