QueenR February 2016

Redirecting the previous page after deleting a record

I'm a newbee in CI. I'm hoping that you can help me with my problem. :) I am trying to redirect the previous page in my site which has the table containing the data from the database. I keep on getting the message

Fatal error: Call to a member function result() on a non-object in C:\xampp\htdocs\..... 
Call to a member function result() on a non-object in C:\xampp\htdocs\findiningcebu.com\application\views\admin\SearchRestoDisplay.php on line 122

and the notice that says

Undefined variable: restaurantinfo....Backtrace:    
File: C:\xampp\htdocs\findiningcebu.com\application\views\admin\SearchRestoDisplay.php
Line: 122

Here are my codes:

View:

<div class = "list">
<table border=2>
<tr style="font-size: 16px; background-color: rgba(26, 26, 38, 0.5);">
<th>Name</th>
<th>Logo</th>
<th>Cuisine</th>
<th>Action</th>
</tr>

    <?php
      $restoname= ''; 
      $restologo= '';
      $cuisine= '';

      foreach($restaurantinfo->result() as $row) 
      { 
        $restoname= $row->restoname; 
        $restologo= $row->restologo;
        $cuisine= $row->cuisine;
       ?>

Controller:

public function delete($id)
{
    $this->load->model('AdminModel');
    $delete = $this->AdminModel->delete($id);
    $this->load->view('admin/SearchRestoDisplay');
}

 public function searchresto()
{
    $restoinfo = $_POST['restoinfo'];
    $searchinfo = $_POST['searchinfo'];

    $this->load->model('AdminModel');
    $restaurantinfo['restoinfo'] = $restoinfo;
    $restaurantinfo['searchinfo'] = $searchinfo;
    $restaurantinfo['restaurantinfo']=$this->AdminModel->searchrestaurant($restoinfo,$searchinfo);
    $this->load->view('admin/SearchRestoDisplay',$restaurantinfo);
}

Model:

public function delete($id)        

Answers


David Bm February 2016

This is happening because result() is a method of the database class and you are trying to use this method on your $restaurantinfo and this looks like a simple array.

I recommend you that your $this->AdminModel->searchrestaurant returns something like this

 function searchrestaurant(){
   /*stuff*/
   return $query->result_array(); 
}

this way you can simply foreach this on your view

foreach($restaurantinfo as $row) 
      { 
        $restoname= $row['restoname']; 
        $restologo= $row['restologo'];
        $cuisine= $row['cuisine'];
      }

The problem looks like you are trying to use a method of the database class on your view, where your query does not exists.

So, change the searchrestaurant function, or do the query on the view.. thing that I don't really recommend...

Hope that helps


Sharmistha Das February 2016

In your delete function when you load the view, you don't pass the value '$restauranrinfo' that's why the restaurant details is missing in view. Fetch the restaurant details from database before load the view and pass the value in view.

Post Status

Asked in February 2016
Viewed 3,988 times
Voted 6
Answered 2 times

Search




Leave an answer