• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
result from query

#1
[eluser]senjy[/eluser]
Hi,

I guess wthy in my model, i have 0 result when i do this with object return.

Model "queries"
Code:
function get_data() {
        $query = $this->db->query("....");
        return $query->result();  
    }
return null

but when it's array, it's ok.

Code:
function get_data() {
        $query = $this->db->query("....");
        return $query->result_array();  
    }
return many data

my Controller
Code:
$this->load->model('queries'); // model
        $data['query'] = $this->requetes->get_data();
        echo '<pre>';
        var_dump($data['query']);
        echo '</pre>';

what's wrong ?

#2
[eluser]marjune[/eluser]
when your using this code below
Code:
function get_data() {
        $query = $this->db->query("....");
        return $query->result();  
}

your controller

Code:
$this->load->model('queries'); // model
$data = $this->requetes->get_data();
foreah($data as $data){
   echo $data->fieldname;
}

#3
[eluser]senjy[/eluser]
display error
Code:
Fatal error: Cannot access empty property in D:\htdocs\system\database\drivers\mysql\mysql_result.php on line 162

#4
[eluser]InsiteFX[/eluser]
Because it returns an empty array! You need to check your returned values for errors and no records.

InsiteFX

#5
[eluser]marjune[/eluser]
Code:
function get_data() {
        $query = $this->db->query("....");
        if($query)
           return $query->result();  
        else
           return 0;
}

#6
[eluser]senjy[/eluser]
if i use $query->result() i don't have result

but

if i use $query->result_array() it's ok

#7
[eluser]marjune[/eluser]
did you try this
Code:
function get_data() {
        $query = $this->db->query("....");
        if($query)
           return $query->result();  
        else
           return 0;
}
Code:
$this->load->model('queries'); // model
$data = $this->requetes->get_data();
foreah($data as $data){
   echo $data->fieldname;
}

#8
[eluser]InsiteFX[/eluser]
Code:
function get_data()
{
    $query = $this->db->query("....");

    if($query->num_rows() > 0)
    {
        return $query->result();
    }
    else
    {
        return FALSE;
    }
}

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.