CodeIgniter Forums
CodeIgniter embedding database results in different html tags ( newbie here.. ) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CodeIgniter embedding database results in different html tags ( newbie here.. ) (/showthread.php?tid=6661)



CodeIgniter embedding database results in different html tags ( newbie here.. ) - El Forum - 03-06-2008

[eluser]Unknown[/eluser]
I am a Codeigniter newbie, and here is my question I know that you get data from your database in an array form. But how do I seperate Data into seperate pieces so I can apply different html tags and CSS to different categories. For ex.

In my Database I have 6 Categories which are:

- Employee_id
- Real_name
- Email
- Profile
- Position
- SSS_number

Ok, so I do a foreach($data as $result) to get the result. In my page I wanna do this.

<h1>&lt;?php $Real_name ?&gt;</h1>
<h2>&lt;?php $Email ?&gt;</h2>
<p>&lt;?php $Profile ?&gt;</p>
<p>&lt;?php $position ?&gt;</p>
<p>&lt;?php $SSS_number ?&gt;</p>

How do I do that?


CodeIgniter embedding database results in different html tags ( newbie here.. ) - El Forum - 03-06-2008

[eluser]Chris Newton[/eluser]
Depending on how your $data is formatted, either access it as an object, or as an array

$Real_name=$result->Real_name;

OR

$Real_name=$result['Real_name'];


CodeIgniter embedding database results in different html tags ( newbie here.. ) - El Forum - 03-07-2008

[eluser]dark_lord[/eluser]
In the Controller
Code:
$query['data'] = $this->db->get('mytable');
$this->load->view('show_data', $query);


In the view: Pass you data from the query array using foreach.

Code:
foreach ($data->result() as $row)
{
    echo $row->id;
    echo $row->username;
}

try this... Smile Hope it works..


CodeIgniter embedding database results in different html tags ( newbie here.. ) - El Forum - 03-07-2008

[eluser]Avatar[/eluser]
in your views if you use
Code:
&lt;?php $blah?&gt;
wont work, have to use either:
Code:
&lt;?=$blah?&gt;
which does echo with semicolon or do this:
Code:
&lt;?php echo $blah; ?&gt;
foreach
Code:
&lt;?php foreach($blah->result() as $poop)?&gt;
&lt;?=$poop?&gt;
&lt;?php endforeach;?&gt;
hope this helps