Search code examples
phpcodeigniteractiverecordresultset

How to return a class without array in Code Igniter


I have function that returns a Class in Array like this :

function getInfo($ev_id){
    $query = $this->db->query("SELECT * FROM events,users 
    where events.ev_user_id = users.id  
    and ev_id = $ev_id");
    $result = $query->result();
    return $result[0];        
}

This function returns a data Array, so I need to use the result to put it in input type to show it for user.

I need to use :-

$eventinfo->ev_text

Not to use an fetch array to display it like $eventinfo->ev_text


Solution

  • use

    $query->row() instead of $query->result()

     $result = $query->row();
        return $result;  
    

    now you can use

    $eventinfo->ev_text
    

    with out looping