I'm having this code shown below but when it is running it's always gives an error saying Message: Undefined variable: result why is it giving that error i can't figure it out ,Can anyone give me a solution please?
myads_model.php
<?php
class Myads_model extends CI_Model
{
public function __construct()
{
$this->load->database();
}
public function getmyads( $SESSION['$email'] )
{
$this->db->select('Vehicleid,Image1,Brand,Model,Modelyear,
VehicleCondition,Mileage,BodyType,Transmission,
Fueltype,EngineCapacity,Price,Negotiable,
Description,Phone,Email');
//$this->db->from('vehicle');
$this->db->where('Email',$SESSION['$email']);
$query=$this->db->get('vehicle');
return $result=$query->result();
}
}
?>
myads_ctrl.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
*
*/
class Myads_ctrl extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function index()
{
$data=array();
$this->load->model('myads_model');
$this->data['result']=$this->myads_model->getmyads($_SESSION['email']);
$this->load->view('pages/templates/header');
$this->load->view('pages/myads_view', $this->data);
$this->load->view('pages/templates/footer');
}
}
?>
myads_view.php
<?php $image=$post->Image1;
$vehicleid=$post->Vehicleid;
echo '<img src="http://localhost/ci/images/' . $image . '" style="width:200px; height:150px;"/>';?>
<?php echo $post->Brand . " " . $post->Model . " " . $post->Modelyear;?>
<b>BRAND: <?php echo $post->Brand;?></b>
<b>MODEL : </b><?php echo $post->Model;?>
<b>MODEL YEAR : </b><?php echo $post->Modelyear;?>
<b>CONDITION : </b>
<?php echo $post->VehicleCondition;?>
<b>MILEAGE : </b><?php echo $post->Mileage;?>KM
<b>TRANSMISSION: </b><?php echo $post->Transmission;?>
<b>FUEL TYPE: </b><?php echo $post->Fueltype;?>
<b>Rs. </b><?php echo $post->Price;?>
<a href="<?php echo 'adpreview_ctrl/getad_preview/'.$vehicleid?>"><input type="button" value="View" class="btn-primary"></a>
In your model do not name parameter as $SESSION['$email']
, instead do $email
. And change your select statement in the model to:
public function getmyads( $email )
{
$this->db->select('your fields here');
$this->db->from('vehicle');
$this->db->where('Email', $email);
$query = $this->db->get();
$result = $query->result();
return $result->num_rows() > 0 ? $result->result_array() : false;
}
In your controller:
$this->data['result']=$this->myads_model->getmyads($_SESSION['email']);
$this->load->view('pages/templates/header');
$this->load->view('pages/myads_view', $this->data);
$this->load->view('pages/templates/footer');
And in your view you should be able to access your result like:
var_dump($result);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.