Get results from database in an array
Posted: Wed May 30, 2012 4:08 pm
I am trying to create a function to get all results from the database and store it in an array so I can do this:
so far I have this,
but it only returns title_en, nothing else. How can I add more columns to it? Or even better get all the columns for each row in the query?
Code: Select all
$news_entries = $news->get_all();
echo $news_entries[1]['title_en']; //shows the title_en of the entry with id=1
echo $news_entries[1]['content_en']; //shows the content_en of the entry with id=1
echo $news_entries[4]['content_en']; //shows the content_en of the entry with id=4Code: Select all
$array = array();
$sql_result = $this->db_object->query("SELECT * FROM `".$this->entries_table."`");
while ($row = $this->db_object->fetch_array($sql_result)) {
$array[$row['id']] = $row['title_en'];
}
return $array;