CodeIgniter Forums

Full Version: View
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
function display(){
$img_id = 1;
$this->load->database();
$this->db->select('img_name, img_id');
$query = $this->db->get('upload',array('img_id' => $img_id ));
echo "<pre>"; print_r($query);echo "</pre>";
echo "<pre>"; print_r($this->db->get('upload'));echo "</pre>";
foreach ($query->result() as $row)
{
echo "<pre>"; print_r($row);echo "</pre>";
$temp['image']['img_id'] = $row->img_id;
$temp['image']['img_name'] = $row->img_name;
}
$this->load->view('showImage');

}
&lt;?php foreach($image as $row):?&gt;
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Image Id</td>
<td>
&lt;?php echo $row['img_id'];?&gt;
</td>
</tr>
<tr>
<td>Image Name</td>
<td>
&lt;?php echo $row['img_name'];?&gt;
</td>
</tr>
</table>
&lt;?php endforeach;?&gt;


I have this funcion, in Controller, and I want to display it in View, I have tried it alot, but I can't write its View File,and I get these errors while... Help me, cz i m hanged

El Forum

[eluser]Phil Sturgeon[/eluser]
Instead of echoing, just assign it to a variable.

Code:
function display(){
  $img_id = 1;
      $this->load->database();
      $this->db->select('img_name, img_id');
      $query = $this->db->get(‘upload’,array('img_id' => $img_id ));
      $data['output'] = '<pre>'.print_r($query, TRUE).'</pre>';
      $data['output'] .= '<pre>'.$this->db->get('upload').'</pre>';

      foreach ($query->result() as $row)
      {
        $data['output'] = '<pre>'.print_r($row, TRUE).'</pre>';
        $temp[‘image’][‘img_id’] = $row->img_id;
        $temp[‘image’][‘img_name’] = $row->img_name;
      }

      $this->load->view('showImage', $data);

  }

El Forum

[eluser]Unknown[/eluser]
A PHP Error was encountered

Severity: 4096

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

Filename: controllers/upload.php

Line Number: 67
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: temp

Filename: views/showImage.php

Line Number: 1
A PHP Error was encountered
these errors arose after using the follow up function

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/showImage.php

Line Number: 1