Welcome Guest, Not a member yet? Register   Sign In
delete function not working need help!!!!!
#1

[eluser]ede196620[/eluser]
Hi everyone i am trying to add a delete function to my project where a row in a table is deleted when a button is clicked but fore some reason that my noob brain cant figure out i am getting an error.

here is the error:
Code:
Fatal error: Call to undefined method Display_model::delete_row() in C:\wamp\www\Surva\application\controllers\display.php on line 34

and here is the rest of my code :

CONTROLLER

Code:
function delete(){
         $this->load->model('display_model');
         $this->display_model->delete_row();
         $this->index();
        
     }

VIEW

Code:
<?php if(isset($queries)) : foreach($queries as $row): ?>  
                 <tr>
                     <td> &lt;?php echo  $row->Question; ?&gt;</td>
                     <td> &lt;?php echo $row->qA; ?&gt; </td>
                     <td>  &lt;?php echo $row->qB; ?&gt;</td>
                     <td> &lt;?php echo $row->qC; ?&gt;</td>
                     <td>&lt;?php echo anchor('display/edit','Edit'); ?&gt;</td>
                     <td>&lt;?php echo anchor('display/delete','Delete'); ?&gt;</td>
                </tr>
                
               &lt;?php endforeach; ?&gt;
                &lt;?php else : ?&gt;
                <h1>No records created </h1>
                &lt;?php endif; ?&gt;
             </table>
            
        &lt;?php if (strlen($pagination)): ?&gt;        
             <div>
                 Pages: &lt;?php echo $pagination; ?&gt;
             </div>
            
          &lt;?php endif; ?&gt;    
    &lt;?php echo anchor('home', 'Back to Dashboard'); ?&gt;

MODEL

Code:
function delete()
          {
             $this->db->where('QID', $this->url->segment(3));
             $this->db->delete('tblquestions');
          }
#2

[eluser]Otemu[/eluser]
Hi,

Your getting this error because your trying to call a function that doesn't exist

your calling
Code:
$this->display_model->delete_row();
when your model function is just called delete

Hope that helps
#3

[eluser]ede196620[/eluser]
tnx for posting. I did realize that and tried to change to delete as i am calling that model function delete but when i change the name i get these two errors:


Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Display::$url

Filename: core/Model.php

Line Number: 51


Code:
Fatal error: Call to a member function segment() on a non-object in C:\wamp\www\Surva\application\models\display_model.php on line 31
#4

[eluser]ede196620[/eluser]
there was a typo instead of url it should be uri Smile

now i am getting this error is there something missing ?

Fatal error: Call to undefined method Display::index() in C:\wamp\www\Surva\application\controllers\display.php on line 35
#5

[eluser]Otemu[/eluser]
You have the following code:

Code:
$this->index();

This is looking for
Code:
public function index()
{
  //your code
}

Do you have this in your controller?
#6

[eluser]ede196620[/eluser]
no i do not this is my full controller page :

Code:
&lt;?php

  class Display extends CI_Controller{
    
      public function displayy($offset = 0)
  
    {
           $limit = 5;
           $this->load->model('display_model');

            $results = $this->display_model->search($limit, $offset);
        
            $data['queries'] = $results['rows'];
            $data['num_results'] = $results['num_rows'];
            
            //pagination
            $this->load->library('pagination');
            $config = array();
            $config['base_url'] = site_url('display/displayy');  
            $config['total_rows'] =  $data['num_results'];
            $config['per_page'] = $limit;
            $config['url_segment'] = 3;
            $this->pagination->initialize($config);      
            $data['pagination'] = $this->pagination->create_links();
            

            $this->load->view('display_view',$data);
        
        
    }
    
      function delete(){
         $this->load->model('display_model');
         $this->display_model->delete_row();
         $this->index();
        
     }

    
    
}

?&gt;
#7

[eluser]ede196620[/eluser]
is there something i can replace that line of code something else ?
#8

[eluser]Otemu[/eluser]
This refers to nothing in your controller

Code:
$this->index();

So now it depends what you want to do next, if you wanted to call your

Code:
public function displayy

then use

Code:
$this->displayy();

#9

[eluser]ede196620[/eluser]
that did fix the error tnx for the help, but the delete function dose not delete anything .
#10

[eluser]TheFuzzy0ne[/eluser]
How does your delete method know what to delete? Or is this the result of some seriously clever programming that can read minds? Smile




Theme © iAndrew 2016 - Forum software by © MyBB