Welcome Guest, Not a member yet? Register   Sign In
can't get data from databse
#1

[eluser]almarjin[/eluser]
Hi,

I just can't get data from my database using the code below I followed the video tutorial and now I'm creating a website but this code does'nt work.

on the controller
$data['query'] = $this->db->get('phones');

on the view
<?php foreach($query->result() as $row):?>
<h3>&lt;?=$row->phone?&gt;</h3>
<p>&lt;?=$row->userid?&gt;</p>
<p>&lt;?=anchor('blog/comments/'.$row->id, 'Comment');?&gt;</p>
<hr>
&lt;?php endforeach;?&gt;

if I try to echo the $query the error below appears

A PHP Error was encountered
Severity: 4096

Message: Object of class CI_DB_mysql_result could not be converted to string

Filename: phones/detail.php

Line Number: 135


thanks
#2

[eluser]drewbee[/eluser]
Did you pass the query result to the view?

Code:
$this->load->view('viewphones', $data);

?
#3

[eluser]phpoet[/eluser]
Is your call to echo in the controller or the view? It seems like either you aren't passing your $data array to your view like drewbee suggested or your database table is empty.
#4

[eluser]almarjin[/eluser]
I just used the code below

function index()
{
$data['leftpanel'] = $this->config->item('FAL_template_dir').'template/subcontent/leftpanel';
$data['heading'] = 'Manage Phone List';
$data['action'] = 'View Phone List';
$data['controller'] = 'phones';
$data['page'] = $this->config->item('FAL_template_dir').'phones/detail';
$data ['query'] = $this->phonelist->getPhoneEntries(getUserProperty('id'))->row_array(); // for phone

$this->load->vars($data);
$this->load->view($this->_container);
}

thanks for your time.
#5

[eluser]almarjin[/eluser]
Now it's working. There's somthing wrong with my "phonelist" function on the ID I changed the code.

But still if I print_r the data. I only got the data from the ID #2

2 (this is the id)
2 (this is the userid)
68454564 (this is the cellnumber)
joel (and the name)

But the others did'nt appear.

again thanks for your time.




Theme © iAndrew 2016 - Forum software by © MyBB