Home > Net >  delete max value from column
delete max value from column

Time:02-19

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);

  }

CodePudding user response:

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 ) ')

CodePudding user response:

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

  • Related