Welcome Guest, Not a member yet? Register   Sign In
In what format is the data stored
#1

[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
--------------------
&lt;?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
--------------------
&lt;?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">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?php echo $header;?&gt;</h1>
<p></p>
<table border="1" cellpadding="5">
&lt;?php foreach($query->result() as $row):?&gt;
<tr>
<td>&lt;?php echo $row->id;?&gt;</td>
<td>&lt;?php echo $row->name;?&gt;</td>
<td>&lt;?php echo $row->email;?&gt;</td>
<td>&lt;?php echo $row->notes;?&gt;</td>
<td>&lt;?php echo $row->t_stamp;?&gt;</td>
<td>&lt;?php echo $row->ipaddress;?&gt;</td>
</tr>
&lt;?php endforeach;?&gt;
</table>
<p></p>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]InsiteFX[/eluser]
Then read the system/database/DB_active_rec.php class

That's how you find out how something works!

Please next time you post code wrap it in code tags!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB