[eluser]neilw[/eluser]
Hello,
I'm brand new to code igniter and it's looking really good
However, I'm having a couple of problems which I imagine are embarrassingly simple. I decided to do a simple test of retrieving data from a database and outputting the contents to the screen using a controller/view (without the model):
1.
In my controller class I added this function:
Code:
function games()
{
$this->load->database();
$query=$this->db->get('retro_games');
$ret="";
foreach($query->result() as $row) {
$ret .= $row->name . '<br />';
}
$data['gamelist']=$ret;
$this->load->view('gameslist',$data);
}
In my view I first tried to view it:
Code:
<body>
<?php echo $gamelist;
?>
</body>
All works fine, however I wanted to take the string generation out of the controller and put it in the view so that the view can determine how to view the data, but I can't figure out how to correctly pass in and iterate through the data. I tried passing in $query, e.g.
$this->load->view('gameslist',$query);
but I don't know what to do in the view as you don't get $query, but the contents of it. I tried passing in $query->result(); but again I didn't know what to use in the for loop, e.g.
<?php foreach($xxxxx as $row) {} ?>
Can anyone help?
2.
In my controller I thought I put in a correct bit of code, which turned out to be wrong, however no errors are generated and there is nothing in the log file, I simply get a completely blank screen with no generated html. Errors are turned on and I've got the log set to everything, e.g. following my code above I tried to chain things together:
$query=$this->db->get('retro_games')->order_by('name','asc');
But there was no error and the view wasn't called afterwards as there was no html? This also happened in my view where I put the wrong syntax in some php, btw.
Many thanks.