Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete multiple rows?

So I can delete one row using:

$this->db->delete($tableName,array("id"=>4));

...but I can't figure out how to delete multiple rows. I tried:

$this->db->delete($tableName,array("id"=>4,"id"=5));

as well as:

$this->db->delete($tableName,array(array("id"=>4),array("id"=5)));

...but they both don't work. I feel like this should be pretty easy. Any answers?

like image 328
Joe Avatar asked May 08 '12 03:05

Joe


People also ask

How do I delete thousands of rows in Excel?

There is also a very handy keyboard shortcut to delete rows (columns or cells). Press Ctrl + – on the keyboard. That's it! Our blank rows are gone now.

What is the shortcut to delete multiple rows?

If you want to delete multiple rows or columns at the same time, you can use the Ctrl+Shift+- shortcut. Simply select the rows or columns you want to delete, and then press the Ctrl+Shift+- keys on your keyboard. All of the selected rows and columns will be deleted.


2 Answers

Have you tried this ?

$names = array(4,5);
$this->db->where_in('id', $names);
$this->db->delete('mytable');
like image 169
Moyed Ansari Avatar answered Sep 17 '22 19:09

Moyed Ansari


not need of associative array.

$ids[] = 1;
$ids[] = 2;

$this->db->where_in( id, $ids );
$this->db->delete('Table_Name');
like image 22
Abuzer Firdousi Avatar answered Sep 19 '22 19:09

Abuzer Firdousi