Welcome Guest, Not a member yet? Register   Sign In
Generating SQL statements
#1

[eluser]pyronate[/eluser]
Pardon if there is a simple way to do this but I am new to CodeIgniter Smile. What’s the best way to delete a bunch of id’s from a table using the $this->db->delete function? I currently get a bunch of "components" from a view and from the model I get the following array contained in components[] and is as such:

Code:
Array
(
    [0] => 57
    [1] => 58
    [2] => 56
    [3] => 38
    [4] => 46
    [5] => 34
    [6] => 52
    [7] => 53
    [8] => 44
    [9] => 49
    [10] => 41
    [11] => 43
    [12] => 45
    [13] => 47
    [14] => 48
    [15] => 50
    [16] => 51
    [17] => 55
    [18] => 39
    [19] => 37
)
What’s the best way to generate the SQL query "DELETE from components where id=57 etc…" using code igniter?
#2

[eluser]cahva[/eluser]
Code:
$this->db->where_in('id',$array)->delete('components');

That would create SQL to something like this:
Quote:DELETE FROM components WHERE id IN (57,58,56,...);




Theme © iAndrew 2016 - Forum software by © MyBB