Reputation: 37
an update from my previous question..
this is my code in the model.
function member_here()
{
$this->db->select('');
$this->db->from('membership');
$this->db->where('username',$this->input->post('username'));
$q=$this->db->get();
if($q->num_rows() > 0) {
$data = array('first_name');
foreach($q->result() as $row) {
$data=$row;
}
return $data;
}
}
and this is my code in the view form:
<?php
$CI =& get_instance();
$CI->load->model('membership_model');
$result = $CI->membership_model->member_here();
print_r($result);
?>
now. i have a problem.
the output is this:
stdClass Object ( [id] => 10 [first_name] => Marishka [last_name] => Villamin [username] => marishkapv [password] => 01aef487205966f24dd694ca4153ccbb [email_address] => [email protected] )
i dont need that output. instead i want my output to be Marishka which is the value of the first_name field.
help please
Upvotes: 1
Views: 1176
Reputation: 36
I guess your problem has been solved, but next time, you could specify the particular column you wish to fetch from your database.
function member_here()
{
//This is where your specify the column
$this->db->select('first_name');
$this->db->from('membership');
$this->db->where('username',$this->input->post('username'));
$q=$this->db->get();
if($q->num_rows() > 0) {
$data = array('first_name');
foreach($q->result() as $row) {
$data=$row;
}
return $data;
}
}
Like so..
I hope this was helpful
Upvotes: 0
Reputation: 18695
echo $result->first_name;
You just need to echo out the part of the object you want, not the entire object. And for the record you shouldn't be getting any data from the model in the view, that should all be done in the controller.
Upvotes: 3