skip to Main Content

i have problem when executed this code in CodeIgniter it deletes all records not only the max value record although it works fine if i execute Sql query in phpmyadmin what wrong in PHP code
my code:

controller:

            $this->data->del_data_query('DELETE FROM `sessions` WHERE 
          sessions.name = 
            "dina" and id = (select max(id) from `sessions` ) ');

  Model:

  public function del_data_query($query)

  {

    $this->db->query($query);

  }

2

Answers


  1. This should do the trick. Also make sure that your id column is index = UNIQUE and is intiger

    id = (select id from `sessions` ORDER BY id DESC limit 1 ) ')
    
    Login or Signup to reply.
  2. The query is correct: i tried it on my db.

    Are you sure that, for some reason, your php didn’t call del_data_query more than one times?

    You could use some debug to test it, or more easily, add

    echo 'DONE';

    on end of method

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search