I have a table(myTable) with 3 fields:
ID (int), posistion(int), products_id(int)
I have an form where we can change the order, and remove items from/in this list. After the user is done editing the list he submits the form.
I want to empty out the table before inserting the new data.
so i call $this->db->empty_table("myTable");
After that i insert the new data like this:
$this->db->insert_batch("jcarousel",$insert);
The problem is: somehow the empty_table() is called after the insert query, because my table always is empty. To be clear: My insert query is working fine when i comment out //$this->db->empty_table("myTable");
i have tried a couple of things, so my code i a bit messed up. Right now it looks like this:
public function change_carousel_order($value='')
{
$this->output->enable_profiler(TRUE);
$empty = $this->empty_table();
//$empty = TRUE;
$form = $this->input->post();
//print_r($form['order']);
$insert = array();
foreach ($form['order'] as $key => $value) {
//echo "value: ".$value;
$insert[$key]['product_id'] = $value;
$insert[$key]['posistion'] = $key;
}
echo $this->db->last_query();
if($empty==TRUE)
{
echo "jaaa";
echo $this->insert_change_carausel_order($insert);
}
else{
echo "neee!";
}
echo $this->db->last_query();
//redirect("welcome/jcarousel");
}
public function empty_table($value='')
{
return $this->db->empty_table("jcarousel");
}
public function insert_change_carausel_order($insert=array())
{
return $this->db->insert_batch("jcarousel",$insert);
}
Anyone who see what i am doing wrong? Why is'nt codeigniter inserting any data after empty_table() is called? Any help would be great full appreciated.
$this->output->enable_profiler(TRUE); tells us that there are 2 queries; the delete query runs indeed AFTER the insert query
0.0003 DELETE FROM `jcarousel`
0.0002 INSERT INTO `jcarousel` (`posistion`, `product_id`) VALUES (0,'755'), (1,'835'), (2,'838')
and another result same setup:
0.0006 DELETE FROM `jcarousel`
0.0002 INSERT INTO `jcarousel` (`posistion`, `product_id`) VALUES (0,'755'), (1,'835'), (2,'838')
var_dump($empty)?echo $this->db->last_query();after$this->insert_change_carausel_order($insert);jcarousel(posistion,product_id) VALUES (0,'755'), (1,'835'), (2,'838')change_carousel_orderfunction. can you paste that code as well