Welcome Guest, Not a member yet? Register   Sign In
single view image
#1

[eluser]shiva478[/eluser]
Hi

I'm trying to view a row with information in it. For example I have a list of titles and if I click the view link it has to give me all the information of that title.

I have managed to do half of it, I get the title and the content but not the image.
The error that I get is

Quote:A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: bras/bra_view.php

Line Number: 7

http://localhost/CodeIgniter_2.1.2/uploads/" />
and I get a broken picture

This is my controller
Code:
class Admin extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->helper('form');
  $this->load->helper('url');
}

function bras() {

  $data['title'] = "Voluptuous Decadents";
  $data['heading'] = "Bras";
  
  $data['query'] = $this->db->get('bras');
  
  //$this->load->view('layout');  
  
  $this->load->view('admin/bras/bras', $data);
  //print_r($data);
  
  
}

function bra_view($bra_id)
{
  $data['bra_item'] = $this->admin_model->get_bras($bra_id);

if (empty($data['bra_item']))
{
  show_404();
}

$data['title'] = $data['bra_item']['title'];

//$this->load->view('templates/header', $data);
$this->load->view('admin/bras/bra_view', $data);
//$this->load->view('templates/footer');
}

and this is my model
Code:
class Admin_model extends CI_Model
{

public function get_bras($bra_id = FALSE)
{
if ($bra_id === FALSE)
{
  $query = $this->db->get('bras');
  return $query->result_array();
}

$query = $this->db->get_where('bras', array('bra_id' => $bra_id));
return $query->row_array();
}

this is my bras view
Code:
Bras view
<html>
<head>

<title><?php echo $title; ?></title>
</head>
<body>
<h1>&lt;?php //echo $heading ?&gt;</h1>
&lt;?php echo anchor('admin/bra_create', 'Create'); ?&gt;<br />


&lt;?php foreach($query->result() as $row): ?&gt;

&lt;?php echo $row->title ?&gt;<br />

&lt;?php echo anchor("admin/bra_view/$row->bra_id", 'view');?&gt;

&lt;?php echo anchor("admin/update_bras/$row->bra_id", 'Update');?&gt;
&lt;?php echo anchor("admin/delete_bras/$row->bra_id", 'Delete');?&gt;<br />




&lt;?php endforeach; ?&gt;

&lt;body&gt;
&lt;/html&gt;

and this is my bra_view
Code:
This is the bras view

&lt;?php
echo '<h2>'.$bra_item['title'].'</h2>';
echo $bra_item['content'];
?&gt;
<img src="&lt;?php echo base_url().'uploads/'.$bra_item-&gt;filename; ?&gt;" /><br />
#2

[eluser]gRoberts[/eluser]
You might want to check to see if $query is false or not, as it seems your query is failing for some reason.
#3

[eluser]shiva478[/eluser]
I solved it. I had to change

Code:
<img src="&lt;?php echo base_url().'uploads/'.$bra_item-&gt;filename; ?&gt;" /><br />

to
Code:
<img src="&lt;?php echo base_url().'uploads/'.$bra_item['filename']; ?&gt;" /><br />




Theme © iAndrew 2016 - Forum software by © MyBB