[Solved] Fetch records of a table as an array php mySQL [closed]
$array = array(); while ($row = mysql_fetch_row($result)) { $array[] = $row; } solved Fetch records of a table as an array php mySQL [closed]
$array = array(); while ($row = mysql_fetch_row($result)) { $array[] = $row; } solved Fetch records of a table as an array php mySQL [closed]
You simply have to pass second params of mysqli_fetch_array to get desired result $sql = “SELECT * FROM contacts”; $result = mysqli_query($connect, $sql); $response = array(); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { //<———–change this $response[] = $row; } print json_encode($response); // Close connection mysqli_close($connect); EDIT OR you can use mysqli_fetch_assoc($result) to get associative array See … Read more
In Your model add this method: public function getINFO(){ $query = $this->db->get_where(‘usuarios’, array(‘id’ => $this->session->userdata(‘id’))); if ($query->num_rows() > 0 ) { return $query->row_array(); } } See this link for more : https://www.codeigniter.com/user_guide/database/results.html#result-arrays 18 solved Conditional fetching data from a table
Change getDetails() method by this // $this->session->userdata[‘id’] to this code $this->session->userdata(‘id’) public function getDetails() { $st = $this->db->SELECT(‘cursadas.date as date, cursadas.grade as grade, usuarios.username as user, materias.name as subject’)->from(‘cursadas’) ->join(‘usuarios’,’usuarios.id=cursadas.user_id’) ->join(‘materias’,’materias.id=cursadas.subject_id’) ->WHERE(‘cursadas.user_id=’,$this->session->userdata(‘id’)) ->get()->result_array(); return $st; } see the link for more info https://www.codeigniter.com/user_guide/libraries/sessions.html#retrieving-session-data 3 solved Error after loggin out