Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter embedding database results in different html tags ( newbie here.. )
#1

[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?
#2

[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'];
#3

[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..
#4

[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




Theme © iAndrew 2016 - Forum software by © MyBB