Update query in CodeigniterHow should I choose an authentication library for CodeIgniter?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)CodeIgniter: Create new helper?Assigning variables based on string dataCodeIgniter activerecord, retrieve last insert id?Which version of CodeIgniter am I currently using?How do I write an sql query to display items from 2 tables based on a selection of a criteria which is from a different tablePagination required to limit my .csv file result on my PHP Pageupdating query in codeigniterUpdate query Codeigniter Message

100-doors puzzle

The instant an accelerating object has zero speed, is it speeding up, slowing down, or neither?

Digital signature that is only verifiable by one specific person

How useful is the GRE Exam?

Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?

Can a non-invertible function be inverted by returning a set of all possible solutions?

...and then she held the gun

Print the phrase "And she said, 'But that's his.'" using only the alphabet

How to ask if I can mow my neighbor's lawn

Why can't we feel the Earth's revolution?

How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?

Is there any effect in D&D 5e that cannot be undone?

2 Managed Packages in 1 Dev Org

Numerical second order differentiation

Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?

How to know whether to write accidentals as sharps or flats?

How Linux command "mount -a" works

Do my partner and son need an SSN to be dependents on my taxes?

Does anyone recognize these rockets, and their location?

How can I maintain game balance while allowing my player to craft genuinely useful items?

How do I become a better writer when I hate reading?

High-end PC graphics circa 1990?

Manager wants to hire me; HR does not. How to proceed?

How "fast" does astronomical events happen?



Update query in Codeigniter


How should I choose an authentication library for CodeIgniter?Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)CodeIgniter: Create new helper?Assigning variables based on string dataCodeIgniter activerecord, retrieve last insert id?Which version of CodeIgniter am I currently using?How do I write an sql query to display items from 2 tables based on a selection of a criteria which is from a different tablePagination required to limit my .csv file result on my PHP Pageupdating query in codeigniterUpdate query Codeigniter Message






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to update the data into the database, and must match the two conditions then only will update the data in database.



Please take a look in my Model, there has two condition, which is id and order_id.
When only assign one condition[$this->db->where('order_id',$id);], it works well for one item, but when the order has two item and above, it only can update the data for last row of the order items.



So, I try with two condition, which is [$this->db->where('order_id',$id);] and [$this->db->where('id',$oid);], but it cannot works.



Updated!!



I had changed some codes in controller and model
I get an error:[Array to string conversion],id = Array AND order_id = '10'



Controller:



public function EditOrderPage()
$id = $this->uri->segment(3);
$oid = $this->order->GetCusOrderItemID($id);

$data['title'] = "JCUBE";
$data['orders'] = $this->order->GetCusOrder($id);
$data['orderitems'] = $this->order->GetCusOrderItem($id);
$data['item'] = $this->order->GetItem();
$data['projectcode'] = $this->order->GetProjectCode();
$data['payoption'] = $this->order->GetPayOption();
$data['eppmonth'] = $this->order->GetEppMonth();
$this->load->view('ordering/header',$data);
$this->load->view('ordering/edit_order_page',$data);
$this->load->view('ordering/footer',$data);

if($this->input->post('update')) //if press button 'update order'
$email = $this->input->post('email');
$tel = $this->input->post('telno');
$address = $this->input->post('address');
$projectCode = $this->input->post('projectcode');
$payOption = $this->input->post('options');
$eppMonth = $this->input->post('eppmonth');
$RefOrderID = $this->input->post('ref_order_id');
$remark = $this->input->post('remark');
$grandTotal = $this->input->post('grandtotal');
$this->order->UpdateOrderHeader($email,$tel,$address,$projectCode,$payOption,$eppMonth,$RefOrderID,$remark,$grandTotal,$id);

$post = $this->input->post();
$arraySize = count($post['item_id']);
for($k=0; $k<$arraySize; $k++)
$itemName = $this->order->GetItemName($post['item_id'][$k]);

$productId = $post['item_id'][$k];
$itemName = $itemName['item_name']; //to be search in model using productID
$quantity = $post['qty'][$k];
$weight = $post['weight'][$k];
$transportation = $post['transportation'][$k];
$premium = $post['gp'][$k];
$discount = $post['discount'][$k];
$unitPrice = $post['unit_price'][$k];
$TotalWithoutTax = $post['totalwithouttax'][$k];
$TotalTax = $post['totaltax'][$k];
$TotalAmtInclTax = $post['totalamtincltax'][$k];
$this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id);






Model:



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id',$id);
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id');

$query = $this->db->get();
return $query->result_array();


public function UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id){
$OrderItem = array(
'product_id' => $productId,
'item' => $itemName,
'qty' => $quantity,
'weight' => $weight,
'transportation_price' => $transportation,
'gp' => $premium,
'discount' => $discount,
'unit_price' => $unitPrice,
'amt_without_tax' => $TotalWithoutTax,
'tax' => $TotalTax,
'amt_incl_tax' => $TotalAmtInclTax
);
$this->db->set($OrderItem);
$this->db->where('id',$oid);
$this->db->where('order_id',$id);
$this->db->update('order_items');


View:



<?php
foreach($orderitems as $orderitem) ?>
<tr class="item-details">
<td><input id="orderitems" type="hidden" class="form-control" name="id" value="<?=$orderitem['id']?>" readonly></td>
<td class="">
<?php
$options = array(
'' => '~Choose An Item~'
);
foreach ($item as $rows)
$options[$rows->id] = $rows->item_name;


$select = array(
'name' => 'item',
'id' => 'item_id',
'class' => 'form-control'
);
echo form_dropdown('item_id[]', $options,set_value('item_name',$orderitem['product_id']),$select);
?>
</td>
<td class=""><input type="number" id="qty[]" class="item-qty" name="qty[]" step="1" min="0" value="<?=$orderitem['qty']?>"/></td>
<td><input type="number" name="weight[]" class="weight" step="any" value="<?=$orderitem['weight']?>"/></td>
<td><input type="number" name="transportation[]" class="transporation" step="any" value="<?=$orderitem['transportation_price']?>" readonly/></td>
<td><input type="text" id="gp[]" name="gp[]" value="<?=$orderitem['gp']?>" /></td>
<td><input type="text" id="discount[]" name="discount[]" value="<?=$orderitem['discount']?>" readonly/></td>
<td><input type="text" id="unit_price[]" name="unit_price[]" value="<?=$orderitem['unit_price']?>" /></td>
<td align="right">
<input type="text" id="totalwithouttax[]" name="totalwithouttax[]" value="<?=$orderitem['amt_without_tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totaltax[]" name="totaltax[]" value="<?=$orderitem['tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totalamtincltax[]" name="totalamtincltax[]" value="<?=$orderitem['amt_incl_tax']?>" readonly>
</td>
</tr><br/><br><br><br>
<?php ?>


I wish that I can update the items with these two condition. Hope someone can help me.










share|improve this question
























  • Are you getting any errors?

    – RopAli Munshi
    Mar 25 at 4:24











  • @RopAliMunshi No error, but when i click the update button, nothing changes in the database

    – jovan2226
    Mar 25 at 4:38











  • @jovan2226 are you getting values in $oid and $id?

    – Danish Ali
    Mar 25 at 4:39











  • use update_batch() to update the rows

    – Tom
    Mar 25 at 5:38











  • i cant see $oid,$id in your for loop

    – Abdulla Nilam
    Mar 25 at 5:44

















0















I want to update the data into the database, and must match the two conditions then only will update the data in database.



Please take a look in my Model, there has two condition, which is id and order_id.
When only assign one condition[$this->db->where('order_id',$id);], it works well for one item, but when the order has two item and above, it only can update the data for last row of the order items.



So, I try with two condition, which is [$this->db->where('order_id',$id);] and [$this->db->where('id',$oid);], but it cannot works.



Updated!!



I had changed some codes in controller and model
I get an error:[Array to string conversion],id = Array AND order_id = '10'



Controller:



public function EditOrderPage()
$id = $this->uri->segment(3);
$oid = $this->order->GetCusOrderItemID($id);

$data['title'] = "JCUBE";
$data['orders'] = $this->order->GetCusOrder($id);
$data['orderitems'] = $this->order->GetCusOrderItem($id);
$data['item'] = $this->order->GetItem();
$data['projectcode'] = $this->order->GetProjectCode();
$data['payoption'] = $this->order->GetPayOption();
$data['eppmonth'] = $this->order->GetEppMonth();
$this->load->view('ordering/header',$data);
$this->load->view('ordering/edit_order_page',$data);
$this->load->view('ordering/footer',$data);

if($this->input->post('update')) //if press button 'update order'
$email = $this->input->post('email');
$tel = $this->input->post('telno');
$address = $this->input->post('address');
$projectCode = $this->input->post('projectcode');
$payOption = $this->input->post('options');
$eppMonth = $this->input->post('eppmonth');
$RefOrderID = $this->input->post('ref_order_id');
$remark = $this->input->post('remark');
$grandTotal = $this->input->post('grandtotal');
$this->order->UpdateOrderHeader($email,$tel,$address,$projectCode,$payOption,$eppMonth,$RefOrderID,$remark,$grandTotal,$id);

$post = $this->input->post();
$arraySize = count($post['item_id']);
for($k=0; $k<$arraySize; $k++)
$itemName = $this->order->GetItemName($post['item_id'][$k]);

$productId = $post['item_id'][$k];
$itemName = $itemName['item_name']; //to be search in model using productID
$quantity = $post['qty'][$k];
$weight = $post['weight'][$k];
$transportation = $post['transportation'][$k];
$premium = $post['gp'][$k];
$discount = $post['discount'][$k];
$unitPrice = $post['unit_price'][$k];
$TotalWithoutTax = $post['totalwithouttax'][$k];
$TotalTax = $post['totaltax'][$k];
$TotalAmtInclTax = $post['totalamtincltax'][$k];
$this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id);






Model:



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id',$id);
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id');

$query = $this->db->get();
return $query->result_array();


public function UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id){
$OrderItem = array(
'product_id' => $productId,
'item' => $itemName,
'qty' => $quantity,
'weight' => $weight,
'transportation_price' => $transportation,
'gp' => $premium,
'discount' => $discount,
'unit_price' => $unitPrice,
'amt_without_tax' => $TotalWithoutTax,
'tax' => $TotalTax,
'amt_incl_tax' => $TotalAmtInclTax
);
$this->db->set($OrderItem);
$this->db->where('id',$oid);
$this->db->where('order_id',$id);
$this->db->update('order_items');


View:



<?php
foreach($orderitems as $orderitem) ?>
<tr class="item-details">
<td><input id="orderitems" type="hidden" class="form-control" name="id" value="<?=$orderitem['id']?>" readonly></td>
<td class="">
<?php
$options = array(
'' => '~Choose An Item~'
);
foreach ($item as $rows)
$options[$rows->id] = $rows->item_name;


$select = array(
'name' => 'item',
'id' => 'item_id',
'class' => 'form-control'
);
echo form_dropdown('item_id[]', $options,set_value('item_name',$orderitem['product_id']),$select);
?>
</td>
<td class=""><input type="number" id="qty[]" class="item-qty" name="qty[]" step="1" min="0" value="<?=$orderitem['qty']?>"/></td>
<td><input type="number" name="weight[]" class="weight" step="any" value="<?=$orderitem['weight']?>"/></td>
<td><input type="number" name="transportation[]" class="transporation" step="any" value="<?=$orderitem['transportation_price']?>" readonly/></td>
<td><input type="text" id="gp[]" name="gp[]" value="<?=$orderitem['gp']?>" /></td>
<td><input type="text" id="discount[]" name="discount[]" value="<?=$orderitem['discount']?>" readonly/></td>
<td><input type="text" id="unit_price[]" name="unit_price[]" value="<?=$orderitem['unit_price']?>" /></td>
<td align="right">
<input type="text" id="totalwithouttax[]" name="totalwithouttax[]" value="<?=$orderitem['amt_without_tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totaltax[]" name="totaltax[]" value="<?=$orderitem['tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totalamtincltax[]" name="totalamtincltax[]" value="<?=$orderitem['amt_incl_tax']?>" readonly>
</td>
</tr><br/><br><br><br>
<?php ?>


I wish that I can update the items with these two condition. Hope someone can help me.










share|improve this question
























  • Are you getting any errors?

    – RopAli Munshi
    Mar 25 at 4:24











  • @RopAliMunshi No error, but when i click the update button, nothing changes in the database

    – jovan2226
    Mar 25 at 4:38











  • @jovan2226 are you getting values in $oid and $id?

    – Danish Ali
    Mar 25 at 4:39











  • use update_batch() to update the rows

    – Tom
    Mar 25 at 5:38











  • i cant see $oid,$id in your for loop

    – Abdulla Nilam
    Mar 25 at 5:44













0












0








0








I want to update the data into the database, and must match the two conditions then only will update the data in database.



Please take a look in my Model, there has two condition, which is id and order_id.
When only assign one condition[$this->db->where('order_id',$id);], it works well for one item, but when the order has two item and above, it only can update the data for last row of the order items.



So, I try with two condition, which is [$this->db->where('order_id',$id);] and [$this->db->where('id',$oid);], but it cannot works.



Updated!!



I had changed some codes in controller and model
I get an error:[Array to string conversion],id = Array AND order_id = '10'



Controller:



public function EditOrderPage()
$id = $this->uri->segment(3);
$oid = $this->order->GetCusOrderItemID($id);

$data['title'] = "JCUBE";
$data['orders'] = $this->order->GetCusOrder($id);
$data['orderitems'] = $this->order->GetCusOrderItem($id);
$data['item'] = $this->order->GetItem();
$data['projectcode'] = $this->order->GetProjectCode();
$data['payoption'] = $this->order->GetPayOption();
$data['eppmonth'] = $this->order->GetEppMonth();
$this->load->view('ordering/header',$data);
$this->load->view('ordering/edit_order_page',$data);
$this->load->view('ordering/footer',$data);

if($this->input->post('update')) //if press button 'update order'
$email = $this->input->post('email');
$tel = $this->input->post('telno');
$address = $this->input->post('address');
$projectCode = $this->input->post('projectcode');
$payOption = $this->input->post('options');
$eppMonth = $this->input->post('eppmonth');
$RefOrderID = $this->input->post('ref_order_id');
$remark = $this->input->post('remark');
$grandTotal = $this->input->post('grandtotal');
$this->order->UpdateOrderHeader($email,$tel,$address,$projectCode,$payOption,$eppMonth,$RefOrderID,$remark,$grandTotal,$id);

$post = $this->input->post();
$arraySize = count($post['item_id']);
for($k=0; $k<$arraySize; $k++)
$itemName = $this->order->GetItemName($post['item_id'][$k]);

$productId = $post['item_id'][$k];
$itemName = $itemName['item_name']; //to be search in model using productID
$quantity = $post['qty'][$k];
$weight = $post['weight'][$k];
$transportation = $post['transportation'][$k];
$premium = $post['gp'][$k];
$discount = $post['discount'][$k];
$unitPrice = $post['unit_price'][$k];
$TotalWithoutTax = $post['totalwithouttax'][$k];
$TotalTax = $post['totaltax'][$k];
$TotalAmtInclTax = $post['totalamtincltax'][$k];
$this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id);






Model:



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id',$id);
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id');

$query = $this->db->get();
return $query->result_array();


public function UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id){
$OrderItem = array(
'product_id' => $productId,
'item' => $itemName,
'qty' => $quantity,
'weight' => $weight,
'transportation_price' => $transportation,
'gp' => $premium,
'discount' => $discount,
'unit_price' => $unitPrice,
'amt_without_tax' => $TotalWithoutTax,
'tax' => $TotalTax,
'amt_incl_tax' => $TotalAmtInclTax
);
$this->db->set($OrderItem);
$this->db->where('id',$oid);
$this->db->where('order_id',$id);
$this->db->update('order_items');


View:



<?php
foreach($orderitems as $orderitem) ?>
<tr class="item-details">
<td><input id="orderitems" type="hidden" class="form-control" name="id" value="<?=$orderitem['id']?>" readonly></td>
<td class="">
<?php
$options = array(
'' => '~Choose An Item~'
);
foreach ($item as $rows)
$options[$rows->id] = $rows->item_name;


$select = array(
'name' => 'item',
'id' => 'item_id',
'class' => 'form-control'
);
echo form_dropdown('item_id[]', $options,set_value('item_name',$orderitem['product_id']),$select);
?>
</td>
<td class=""><input type="number" id="qty[]" class="item-qty" name="qty[]" step="1" min="0" value="<?=$orderitem['qty']?>"/></td>
<td><input type="number" name="weight[]" class="weight" step="any" value="<?=$orderitem['weight']?>"/></td>
<td><input type="number" name="transportation[]" class="transporation" step="any" value="<?=$orderitem['transportation_price']?>" readonly/></td>
<td><input type="text" id="gp[]" name="gp[]" value="<?=$orderitem['gp']?>" /></td>
<td><input type="text" id="discount[]" name="discount[]" value="<?=$orderitem['discount']?>" readonly/></td>
<td><input type="text" id="unit_price[]" name="unit_price[]" value="<?=$orderitem['unit_price']?>" /></td>
<td align="right">
<input type="text" id="totalwithouttax[]" name="totalwithouttax[]" value="<?=$orderitem['amt_without_tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totaltax[]" name="totaltax[]" value="<?=$orderitem['tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totalamtincltax[]" name="totalamtincltax[]" value="<?=$orderitem['amt_incl_tax']?>" readonly>
</td>
</tr><br/><br><br><br>
<?php ?>


I wish that I can update the items with these two condition. Hope someone can help me.










share|improve this question
















I want to update the data into the database, and must match the two conditions then only will update the data in database.



Please take a look in my Model, there has two condition, which is id and order_id.
When only assign one condition[$this->db->where('order_id',$id);], it works well for one item, but when the order has two item and above, it only can update the data for last row of the order items.



So, I try with two condition, which is [$this->db->where('order_id',$id);] and [$this->db->where('id',$oid);], but it cannot works.



Updated!!



I had changed some codes in controller and model
I get an error:[Array to string conversion],id = Array AND order_id = '10'



Controller:



public function EditOrderPage()
$id = $this->uri->segment(3);
$oid = $this->order->GetCusOrderItemID($id);

$data['title'] = "JCUBE";
$data['orders'] = $this->order->GetCusOrder($id);
$data['orderitems'] = $this->order->GetCusOrderItem($id);
$data['item'] = $this->order->GetItem();
$data['projectcode'] = $this->order->GetProjectCode();
$data['payoption'] = $this->order->GetPayOption();
$data['eppmonth'] = $this->order->GetEppMonth();
$this->load->view('ordering/header',$data);
$this->load->view('ordering/edit_order_page',$data);
$this->load->view('ordering/footer',$data);

if($this->input->post('update')) //if press button 'update order'
$email = $this->input->post('email');
$tel = $this->input->post('telno');
$address = $this->input->post('address');
$projectCode = $this->input->post('projectcode');
$payOption = $this->input->post('options');
$eppMonth = $this->input->post('eppmonth');
$RefOrderID = $this->input->post('ref_order_id');
$remark = $this->input->post('remark');
$grandTotal = $this->input->post('grandtotal');
$this->order->UpdateOrderHeader($email,$tel,$address,$projectCode,$payOption,$eppMonth,$RefOrderID,$remark,$grandTotal,$id);

$post = $this->input->post();
$arraySize = count($post['item_id']);
for($k=0; $k<$arraySize; $k++)
$itemName = $this->order->GetItemName($post['item_id'][$k]);

$productId = $post['item_id'][$k];
$itemName = $itemName['item_name']; //to be search in model using productID
$quantity = $post['qty'][$k];
$weight = $post['weight'][$k];
$transportation = $post['transportation'][$k];
$premium = $post['gp'][$k];
$discount = $post['discount'][$k];
$unitPrice = $post['unit_price'][$k];
$TotalWithoutTax = $post['totalwithouttax'][$k];
$TotalTax = $post['totaltax'][$k];
$TotalAmtInclTax = $post['totalamtincltax'][$k];
$this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id);






Model:



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id',$id);
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id');

$query = $this->db->get();
return $query->result_array();


public function UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid,$id){
$OrderItem = array(
'product_id' => $productId,
'item' => $itemName,
'qty' => $quantity,
'weight' => $weight,
'transportation_price' => $transportation,
'gp' => $premium,
'discount' => $discount,
'unit_price' => $unitPrice,
'amt_without_tax' => $TotalWithoutTax,
'tax' => $TotalTax,
'amt_incl_tax' => $TotalAmtInclTax
);
$this->db->set($OrderItem);
$this->db->where('id',$oid);
$this->db->where('order_id',$id);
$this->db->update('order_items');


View:



<?php
foreach($orderitems as $orderitem) ?>
<tr class="item-details">
<td><input id="orderitems" type="hidden" class="form-control" name="id" value="<?=$orderitem['id']?>" readonly></td>
<td class="">
<?php
$options = array(
'' => '~Choose An Item~'
);
foreach ($item as $rows)
$options[$rows->id] = $rows->item_name;


$select = array(
'name' => 'item',
'id' => 'item_id',
'class' => 'form-control'
);
echo form_dropdown('item_id[]', $options,set_value('item_name',$orderitem['product_id']),$select);
?>
</td>
<td class=""><input type="number" id="qty[]" class="item-qty" name="qty[]" step="1" min="0" value="<?=$orderitem['qty']?>"/></td>
<td><input type="number" name="weight[]" class="weight" step="any" value="<?=$orderitem['weight']?>"/></td>
<td><input type="number" name="transportation[]" class="transporation" step="any" value="<?=$orderitem['transportation_price']?>" readonly/></td>
<td><input type="text" id="gp[]" name="gp[]" value="<?=$orderitem['gp']?>" /></td>
<td><input type="text" id="discount[]" name="discount[]" value="<?=$orderitem['discount']?>" readonly/></td>
<td><input type="text" id="unit_price[]" name="unit_price[]" value="<?=$orderitem['unit_price']?>" /></td>
<td align="right">
<input type="text" id="totalwithouttax[]" name="totalwithouttax[]" value="<?=$orderitem['amt_without_tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totaltax[]" name="totaltax[]" value="<?=$orderitem['tax']?>" readonly>
</td>
<td align="right">
<input type="text" id="totalamtincltax[]" name="totalamtincltax[]" value="<?=$orderitem['amt_incl_tax']?>" readonly>
</td>
</tr><br/><br><br><br>
<?php ?>


I wish that I can update the items with these two condition. Hope someone can help me.







php codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 8:53







jovan2226

















asked Mar 25 at 3:56









jovan2226jovan2226

125




125












  • Are you getting any errors?

    – RopAli Munshi
    Mar 25 at 4:24











  • @RopAliMunshi No error, but when i click the update button, nothing changes in the database

    – jovan2226
    Mar 25 at 4:38











  • @jovan2226 are you getting values in $oid and $id?

    – Danish Ali
    Mar 25 at 4:39











  • use update_batch() to update the rows

    – Tom
    Mar 25 at 5:38











  • i cant see $oid,$id in your for loop

    – Abdulla Nilam
    Mar 25 at 5:44

















  • Are you getting any errors?

    – RopAli Munshi
    Mar 25 at 4:24











  • @RopAliMunshi No error, but when i click the update button, nothing changes in the database

    – jovan2226
    Mar 25 at 4:38











  • @jovan2226 are you getting values in $oid and $id?

    – Danish Ali
    Mar 25 at 4:39











  • use update_batch() to update the rows

    – Tom
    Mar 25 at 5:38











  • i cant see $oid,$id in your for loop

    – Abdulla Nilam
    Mar 25 at 5:44
















Are you getting any errors?

– RopAli Munshi
Mar 25 at 4:24





Are you getting any errors?

– RopAli Munshi
Mar 25 at 4:24













@RopAliMunshi No error, but when i click the update button, nothing changes in the database

– jovan2226
Mar 25 at 4:38





@RopAliMunshi No error, but when i click the update button, nothing changes in the database

– jovan2226
Mar 25 at 4:38













@jovan2226 are you getting values in $oid and $id?

– Danish Ali
Mar 25 at 4:39





@jovan2226 are you getting values in $oid and $id?

– Danish Ali
Mar 25 at 4:39













use update_batch() to update the rows

– Tom
Mar 25 at 5:38





use update_batch() to update the rows

– Tom
Mar 25 at 5:38













i cant see $oid,$id in your for loop

– Abdulla Nilam
Mar 25 at 5:44





i cant see $oid,$id in your for loop

– Abdulla Nilam
Mar 25 at 5:44












2 Answers
2






active

oldest

votes


















0














Modify GetCusOrderItemID function like this :



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id item_id');
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id',$id);

$query = $this->db->get();
return $query->result_array();



And change $oid to $oid[$k]['item_id'] in :



$this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid[$k]['item_id'],$id);





share|improve this answer























  • this works well for me, and i just change the item_id to product_id, thanks bro!

    – jovan2226
    Mar 25 at 8:23











  • But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

    – jovan2226
    Mar 25 at 8:38











  • Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

    – user11252866
    Mar 25 at 8:54











  • Choose any name from the database's column, right? Really appreciate for your answer :D

    – jovan2226
    Mar 25 at 9:09


















0














Please Try this,

i Dont know why you used result in model return,but i changed two lines
Model:



public function GetCusOrderItemID($id = NULL)
$this->db->select('oi.id as oid');//changes
$this->db->from('order_items oi');
$this->db->join('order o', 'oi.order_id = o.id');
$this->db->where('o.id');

$query = $this->db->get();
return $query->row('oid');//changes






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331074%2fupdate-query-in-codeigniter%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Modify GetCusOrderItemID function like this :



    public function GetCusOrderItemID($id = NULL)
    $this->db->select('oi.id item_id');
    $this->db->from('order_items oi');
    $this->db->join('order o', 'oi.order_id = o.id');
    $this->db->where('o.id',$id);

    $query = $this->db->get();
    return $query->result_array();



    And change $oid to $oid[$k]['item_id'] in :



    $this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid[$k]['item_id'],$id);





    share|improve this answer























    • this works well for me, and i just change the item_id to product_id, thanks bro!

      – jovan2226
      Mar 25 at 8:23











    • But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

      – jovan2226
      Mar 25 at 8:38











    • Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

      – user11252866
      Mar 25 at 8:54











    • Choose any name from the database's column, right? Really appreciate for your answer :D

      – jovan2226
      Mar 25 at 9:09















    0














    Modify GetCusOrderItemID function like this :



    public function GetCusOrderItemID($id = NULL)
    $this->db->select('oi.id item_id');
    $this->db->from('order_items oi');
    $this->db->join('order o', 'oi.order_id = o.id');
    $this->db->where('o.id',$id);

    $query = $this->db->get();
    return $query->result_array();



    And change $oid to $oid[$k]['item_id'] in :



    $this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid[$k]['item_id'],$id);





    share|improve this answer























    • this works well for me, and i just change the item_id to product_id, thanks bro!

      – jovan2226
      Mar 25 at 8:23











    • But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

      – jovan2226
      Mar 25 at 8:38











    • Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

      – user11252866
      Mar 25 at 8:54











    • Choose any name from the database's column, right? Really appreciate for your answer :D

      – jovan2226
      Mar 25 at 9:09













    0












    0








    0







    Modify GetCusOrderItemID function like this :



    public function GetCusOrderItemID($id = NULL)
    $this->db->select('oi.id item_id');
    $this->db->from('order_items oi');
    $this->db->join('order o', 'oi.order_id = o.id');
    $this->db->where('o.id',$id);

    $query = $this->db->get();
    return $query->result_array();



    And change $oid to $oid[$k]['item_id'] in :



    $this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid[$k]['item_id'],$id);





    share|improve this answer













    Modify GetCusOrderItemID function like this :



    public function GetCusOrderItemID($id = NULL)
    $this->db->select('oi.id item_id');
    $this->db->from('order_items oi');
    $this->db->join('order o', 'oi.order_id = o.id');
    $this->db->where('o.id',$id);

    $query = $this->db->get();
    return $query->result_array();



    And change $oid to $oid[$k]['item_id'] in :



    $this->order->UpdateOrderItems($productId,$itemName,$quantity,$weight,$transportation,$premium,$discount,$unitPrice,$TotalWithoutTax,$TotalTax,$TotalAmtInclTax,$oid[$k]['item_id'],$id);






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 25 at 8:06







    user11252866



















    • this works well for me, and i just change the item_id to product_id, thanks bro!

      – jovan2226
      Mar 25 at 8:23











    • But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

      – jovan2226
      Mar 25 at 8:38











    • Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

      – user11252866
      Mar 25 at 8:54











    • Choose any name from the database's column, right? Really appreciate for your answer :D

      – jovan2226
      Mar 25 at 9:09

















    • this works well for me, and i just change the item_id to product_id, thanks bro!

      – jovan2226
      Mar 25 at 8:23











    • But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

      – jovan2226
      Mar 25 at 8:38











    • Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

      – user11252866
      Mar 25 at 8:54











    • Choose any name from the database's column, right? Really appreciate for your answer :D

      – jovan2226
      Mar 25 at 9:09
















    this works well for me, and i just change the item_id to product_id, thanks bro!

    – jovan2226
    Mar 25 at 8:23





    this works well for me, and i just change the item_id to product_id, thanks bro!

    – jovan2226
    Mar 25 at 8:23













    But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

    – jovan2226
    Mar 25 at 8:38





    But, can you explain to me why change $oid to $oid[$k]['item_id']? Thanks much.

    – jovan2226
    Mar 25 at 8:38













    Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

    – user11252866
    Mar 25 at 8:54





    Glad I could help, to put simply you are calling an update inside the for loop, and $oid is returning arrays set so you need to specify which $oid index you are going to use within that loop, i just changed to item_id to avoid confusion with the order_id but you could choose any name you want :)

    – user11252866
    Mar 25 at 8:54













    Choose any name from the database's column, right? Really appreciate for your answer :D

    – jovan2226
    Mar 25 at 9:09





    Choose any name from the database's column, right? Really appreciate for your answer :D

    – jovan2226
    Mar 25 at 9:09













    0














    Please Try this,

    i Dont know why you used result in model return,but i changed two lines
    Model:



    public function GetCusOrderItemID($id = NULL)
    $this->db->select('oi.id as oid');//changes
    $this->db->from('order_items oi');
    $this->db->join('order o', 'oi.order_id = o.id');
    $this->db->where('o.id');

    $query = $this->db->get();
    return $query->row('oid');//changes






    share|improve this answer



























      0














      Please Try this,

      i Dont know why you used result in model return,but i changed two lines
      Model:



      public function GetCusOrderItemID($id = NULL)
      $this->db->select('oi.id as oid');//changes
      $this->db->from('order_items oi');
      $this->db->join('order o', 'oi.order_id = o.id');
      $this->db->where('o.id');

      $query = $this->db->get();
      return $query->row('oid');//changes






      share|improve this answer

























        0












        0








        0







        Please Try this,

        i Dont know why you used result in model return,but i changed two lines
        Model:



        public function GetCusOrderItemID($id = NULL)
        $this->db->select('oi.id as oid');//changes
        $this->db->from('order_items oi');
        $this->db->join('order o', 'oi.order_id = o.id');
        $this->db->where('o.id');

        $query = $this->db->get();
        return $query->row('oid');//changes






        share|improve this answer













        Please Try this,

        i Dont know why you used result in model return,but i changed two lines
        Model:



        public function GetCusOrderItemID($id = NULL)
        $this->db->select('oi.id as oid');//changes
        $this->db->from('order_items oi');
        $this->db->join('order o', 'oi.order_id = o.id');
        $this->db->where('o.id');

        $query = $this->db->get();
        return $query->row('oid');//changes







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 8:00









        M.HemantM.Hemant

        1,9141413




        1,9141413



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331074%2fupdate-query-in-codeigniter%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript