close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

MySqli update value with itself + new

Thread began 11/19/2019 10:25 am by paulshoe379536 | Last modified 11/20/2019 2:06 pm by paulshoe379536 | 503 views | 5 replies

paulshoe379536

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);
?>

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...