[eluser]swmcl[/eluser]
Hi,
In the following code from a model, I'd like to know what the data is stored as. All the data from the 'contacts' table is placed in a what ... a great big variable ? Is it stored so that the columns are separated by a non-printing character of some sort ? Is the information stored with a <CR><LF> or something like it at the end ? When does all the data get put into an array ? Is it when it is returned from the model ? Although this code does 'work' I am not able to understand what is happening at the foreach loop. If a kind soul could explain I would be very appreciative. My books don't have the construction of the foreach loop written like this and I'm thinking it is a shorthand way of something.
--------------------
THE MODEL
--------------------
<?php
class Cdbtestmodel extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_all_contacts()
{
$query = $this->db->get('contacts');
return $query;
}
}
--------------------
THE CONTROLLER
--------------------
<?php
class Cdbtest extends CI_Controller {
public function index()
{
$data['title'] = 'My test Site';
$data['header'] = 'All of my data';
$this->load->model('Cdbtestmodel');
$data['query'] = $this->Cdbtestmodel->get_all_contacts();
$this->load->view('cdbtestview', $data);
}
}
--------------------
THE VIEW
--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $title;?></title>
</head>
<body>
<h1><?php echo $header;?></h1>
<p></p>
<table border="1" cellpadding="5">
<?php foreach($query->result() as $row):?>
<tr>
<td><?php echo $row->id;?></td>
<td><?php echo $row->name;?></td>
<td><?php echo $row->email;?></td>
<td><?php echo $row->notes;?></td>
<td><?php echo $row->t_stamp;?></td>
<td><?php echo $row->ipaddress;?></td>
</tr>
<?php endforeach;?>
</table>
<p></p>
</body>
</html>