0

i want to save a value from a array to a variable .for doing a if condition check . this is my code inside models folder . i got a errormysqli_fetch_array() expects parameter 1 to be mysqli_result, object given .but the $query returns a array value.

public function this_is_try(){
    $this->db->select('*');
    $this->db->from('partnerprofile');
    $this->db->where('User_Id','20'); 

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

    $row = mysqli_fetch_array($query);
    $user_id = $row['User_Id'];
    $agefrom = $row['AgeFrom'];

    print $user_id;
    exit;
}

2 Answers 2

1

Instead of passing the entire $results(result object). store the result_object to a variable and pass it ie $result=$results[0];

public function this_is_try(){
$this->db->select('*');
     $this->db->from('partnerprofile');
     $this->db->where('User_Id','20');
     $query = $this->db->get();
     $results = $query->result();       
            $result = $results[0];
$user_id=$result->user_id;
$agefrom = $result->AgeFrom;

print $user_id;exit;

}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this :

public function this_is_try(){

$row = $this->db->select('*')
           ->from('partnerprofile');
           ->where('User_Id','20'); 
           ->get()->row();

$user_id = $row->User_Id;
$agefrom = $row->AgeFrom;

print $user_id;exit;

}

3 Comments

i got syntax error syntax error, unexpected '->' (T_OBJECT_OPERATOR) in C:\wamp\www\MilanRishtha\application\models\action_model.php
try $user_id = $row->User_Id; $agefrom = $row->AgeFrom;
While this code snippet may solve the question, including an explanation out of the code really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.