Welcome Guest, Not a member yet? Register   Sign In
Multiple row inserts on db query
#1

[eluser]newbie_codeigniter[/eluser]
Need a little bit of help with transferring php code into codeigniter's coding. I have a form in which an employee can select multiple fields but i need to translate my regular php code into codeigniter's coding and am having a little bit of difficulty figuring it out. Any help would be greatly appreciated thanks. here is the code
Code:
$limit = count($Product);
for($i=0;$i<$limit;$i++) {
$sale_id[$i] = mysql_real_escape_string($sale_id[$i]);
$customer_address[$i] = mysql_real_escape_string($customer_address[$i]);
$customer_borough[$i] = mysql_real_escape_string($customer_borough[$i]);
$delivered[$i] = mysql_real_escape_string($delivered[$i]);
$customer_id[$i] = mysql_real_escape_string($customer_id[$i]);
$driver_id[$i] = mysql_real_escape_string($driver_id[$i]);
$order_cost[$i] = mysql_real_escape_string($order_cost[$i]);

$query = "INSERT INTO delivery_sales(sale_id, customer_address, customer_borough, delivered, customer_id, driver_id, order_cost) VALUES ('".$sale_id[$i]."','".$customer_address[$i]."','".$customer-borough[$i]."','".$delivered[$i]."','".$customer_id[$i]."','".$driver_id[$i]."','".$order_cost[$i]."')";
all of this code corresponds to my view, which has the appropriate field names and id's im just having a lot of difficulty converting this to codeigniter any help would be greatly appreciated. Thanks in advance.
#2

[eluser]superfake123[/eluser]
something along the lines of...

Code:
$data = array(
  'sale_id'           => $sale_id,
  'customer_address'  => $customer_address,
  'customer_borough'  => $customer_borough,
  'delivered'         => $delivered,
  'customer_id'       => $customer_id,
  'driver_id'         => $driver_id,
  'order_cost'        => $order_cost
);

$this->db->insert('delivery_sales', $data);
#3

[eluser]newbie_codeigniter[/eluser]
Thanks but that wont do as I don't see any where in the code you posted that is going to loop thru the array of multiple selects from the view source.
#4

[eluser]superfake123[/eluser]
sorry I thought that part was obvious?

Code:
$limit = count($Product);
for($i=0;$i<$limit;$i++)
{
  $data = array(
    'sale_id'           => $sale_id[$i],
    'customer_address'  => $customer_address[$i],
    'customer_borough'  => $customer_borough[$i],
    'delivered'         => $delivered[$i],
    'customer_id'       => $customer_id[$i],
    'driver_id'         => $driver_id[$i],
    'order_cost'        => $order_cost[$i]
  );
  $this->db->insert('delivery_sales', $data);
}
#5

[eluser]newbie_codeigniter[/eluser]
Thanks for the reply, it should have been obvious. But this day is just getting longer and longer finally gonna get some sleep after 20 hours of non stop going. I do appreciate the help and solution that you have provided me. Still learning the framework and everything that codeigniter has to offer its my first time working with in this environment. So i figure i will hit a few speed bumps along the way but so far so good. Thanks again for the quick reply




Theme © iAndrew 2016 - Forum software by © MyBB