sql - How can I access these data returned by the result_array() function from a PDO query in CodeIgniter? -
public function get_details($id) { //my query in pdo form getting records $query = $this->db->query("select * users idno='". $id ."'"); //check if query successfull if($query) { $query->result_array();//get result through array form print_r($query);//prints array } // end if }//end function
the result of code above this: ci_db_pdo_result object ( [num_rows] => 1 [conn_id] => pdo object ( ) [result_id] => pdostatement object ( [querystring] => select * users idno='888812' ) [result_array] => array ( [0] => array ( [idno] => 888812 [lname] => smith [fname] => john [username] => john [password] => password [usertype] => [status] => ) ) [result_object] => array ( ) [custom_result_object] => array ( ) [current_row] => 0 [row_data] => )
usually result of result_array()
function array of cursor/result query being executed, have problem on how values returned kind of result_array() generated lot of different data along it.
usually result array([id] => 888812, [lname] => smith, [fname] => john, [username] => john, [password] => password.....)
now, why kind of array displayed above? , how able access data?
whenever access data $query['result_array']
or $query['idno']
error fatal error: cannot use object of type ci_db_pdo_result array in c:/.........
$query->result_array();//get result through array form
you aren't assigning returned results of result_array()
anything. when you're running print_r($query)
, you're doing on original query object, not results. result_array()
not change query object reference or anything, need capture results.
$results = $query->result_array(); print_r($results);
drink more coffee or something. :-p
Comments
Post a Comment