Welcome Guest, Not a member yet? Register   Sign In
How to get Insert_batch to upload my arrays when using a Foreach ?
#1

[eluser]vincej[/eluser]
Hi - I have a form which features multiple products with their id's and their prices etc etc. Therefore I have multiple POST arrays coming into my model - They are not single POST values. OK, I want them uploaded into my DB, so, I thought of using a FOREACH and the Insert_batch function to get them uploaded.

my problem is that insert_batch does not upload the values. However, I have experimented with single POST arrays for example $_POST['name'], using the single $this->db->insert and it works. I guess I could create a nest of FOREACH loops, once for each array - but that very messy. Can anyone see what I am doping wrong with this function - why won't it upload my POST arrays - is it possibly exactly because each POST is an array and not a single value.

If that is the case - is there a neater way of doing it without a nest of FOREACH loops ?

Many Thanks !

Here is the query with the broken INSERT_BATCH:

Code:
function confirmed_Order(){

  $prodid = $_POST['prodid'];
  $customerid = $_SESSION['customerid'];

  $data = array(
  'customerid' =>$customerid,
  'quantity' => $_POST['quantity'],
  'Prodname' => $_POST['name'],
  'prodid' => $_POST['prodid'],
  'pricelb' => $_POST['pricelb'],
  'ordervalue'=>$_POST['ordervalue']
  );

  foreach($prodid as $p) {
  $this->db->insert_batch('confirmedorder', $data); //
  }
}





Messages In This Thread
How to get Insert_batch to upload my arrays when using a Foreach ? - by El Forum - 04-26-2012, 03:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB