MySqli update value with itself + new
I'm building a new table using values in "orders" table. The code seems to be working properly by selecting the correct section to process but I am not getting "customer_orders.OrderTotals" to update with it's current value plus the additional value from "orders.OrderSubTotal" when a "customer_orders" already exists.
My code below:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php require_once('../Connections/belles.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php require_once('../webassist/mysqli/queryobj.php'); ?>
<?php
$OnlineOrders = new WA_MySQLi_RS("OnlineOrders",$belles,0);
$OnlineOrders->setQuery("SELECT orders.OrderID, orders.OrderSubTotal, orders.OrderBuyerFirstName, orders.OrderBuyerLastName, orders.OrderEmail FROM orders");
$OnlineOrders->execute();
?>
<?php
$wa_startindex = 0;
while(!$OnlineOrders->atEnd()) {
$wa_startindex = $OnlineOrders->Index;
?>
<?php
$customers1 = new WA_MySQLi_RS("customers1",$belles,1);
$customers1->setQuery("SELECT customer_orders.Email, customer_orders.OrderTotals FROM customer_orders WHERE customer_orders.Email = ?");
$customers1->bindParam("s", "".($OnlineOrders->getColumnVal("OrderEmail")) ."", "-1"); //WAQB_Param1
$customers1->execute();
?>
<?php
if ($customers1->TotalRows > 0) {
$ExecuteQuery = new WA_MySQLi_Query($belles);
$ExecuteQuery->Statement = "UPDATE customer_orders SET customer_orders.OrderTotals = customer_orders.OrderTotals + $OnlineOrders->getColumnVal('OrderSubTotal') WHERE customer_orders.Email = $OnlineOrders->getColumnVal('OrderEmail')";
$ExecuteQuery->execute();
$ExecuteGoTo = "";
if (function_exists("rel2abs")) $ExecuteGoTo = $ExecuteGoTo?rel2abs($ExecuteGoTo,dirname(__FILE__)):"";
$ExecuteQuery->redirect($ExecuteGoTo);
}
?>
<?php
if ($customers1->TotalRows > 0) {
echo ('This is an updated entry >>> ');
echo ('Order Index: '.$OnlineOrders->Index.' - '.$OnlineOrders->getColumnVal("OrderEmail").' - '.$OnlineOrders->getColumnVal("OrderBuyerLastName").' - '.$OnlineOrders->getColumnVal("OrderBuyerFirstName").' - '.$OnlineOrders->getColumnVal("OrderSubTotal")).'<br>';
}
?>
<?php
if ($customers1->TotalRows == 0) {
$InsertQuery = new WA_MySQLi_Query($belles);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "customer_orders";
$InsertQuery->bindColumn("OrderTotals", "d", "".($OnlineOrders->getColumnVal("OrderSubTotal")) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("FirstName", "s", "".($OnlineOrders->getColumnVal("OrderBuyerFirstName")) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("LastName", "s", "".($OnlineOrders->getColumnVal("OrderBuyerLastName")) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("Email", "s", "".($OnlineOrders->getColumnVal("OrderEmail")) ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if ($customers1->TotalRows == 0) {
echo ('This is a new entry >>> ');
echo ('Order Index: '.$OnlineOrders->Index.' - '.$OnlineOrders->getColumnVal("OrderEmail").' - '.$OnlineOrders->getColumnVal("OrderBuyerLastName").' - '.$OnlineOrders->getColumnVal("OrderBuyerFirstName").' - '.$OnlineOrders->getColumnVal("OrderSubTotal")).'<br>';
}
?>
<?php
$OnlineOrders->moveNext();
}
$OnlineOrders->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>