[eluser]daparky[/eluser]
I've ran into a problem while developing an application. Basically what i'm trying to do is get a list of results, explode the id's into comma seperated and perform a where_in delete sql.
My code:
This piece of code is to delete a box as well as all the products within that box.
Code:
$this->db->select('stock_id');
$this->db->where('stock_box', $id);
$products = $this->db->get('stock')->result();
$num = count($products);
if($num > 0)
{
for($i=0; $i<$num; $i++)
{
$product[$i] = $products[$i]->stock_id;
}
$ids = implode(",", $product);
$this->db->where_in('stock_id', $ids);
$this->db->delete('stock');
}
$this->db->where('box_id', $id);
$this->db->delete('box');
When i print_r the $ids it shows them as 1,2,3 etc which is fine but when i print the last query out it shows the result as:-
Code:
WHERE stock_id IN ('1,2,3')
Problem: It needs to have a quotation mark around all of the id numbers instead of around them as a whole. It should be doing this:-
Code:
WHERE stock_id IN ('1','2','3')
This works if i do it in a normal query but i want to use active record. Any help is appreciated.
p.s. this is what i did to solve the issue:-
Code:
$this->db->select('stock_id');
$this->db->where('stock_box', $id);
$products = $this->db->get('stock')->result();
$num = count($products);
if($num > 0)
{
for($i=0; $i<$num; $i++)
{
$this->db->where('stock_id', $products[$i]->stock_id);
$this->db->delete('stock');
}
}
$this->db->where('box_id', $id);
$this->db->delete('box');