简体   繁体   中英

delete max value from column

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

  }

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

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM