close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Subtracting stock quantity for more than 1 item

Thread began 9/08/2010 12:42 am by Badger | Last modified 9/13/2010 7:04 am by Jason Byrnes | 1421 views | 3 replies |

Badger

Subtracting stock quantity for more than 1 item

I'm successfully deleting an eCart's quantity from the field LampInventory on my checkout_success.php based on dlovas275157 solution:

php:
$FinalStack = $eCart1->DisplayInfo("subtractions");

$idProduct = $eCart1->DisplayInfo("ID");

mysql_select_db($database_connChan, $connChan);
$subtractions = mysql_query("UPDATE Lamps SET LampInventory = '$FinalStack' WHERE LampID = '$idProduct'") or die(mysql_error());



How can I make it work for more than just the first item in the cart. Do I need to create an array or loop? If so any examples please.

Thanks

Sign in to reply to this post

Jason ByrnesWebAssist

yes, you need to loop through the cart items.

php:
$eCart1->MoveFirst();

while (!$eCart1->EOF())      {
    $FinalStack = $eCart1->DisplayInfo("subtractions");
    $idProduct = $eCart1->DisplayInfo("ID");

    mysql_select_db($database_connChan, $connChan);
    $subtractions = mysql_query("UPDATE Lamps SET LampInventory = '$FinalStack' WHERE LampID = '$idProduct'") or die(mysql_error());
 $eCart1->MoveNext();
}
$eCart1->MoveFirst();
Sign in to reply to this post

Badger

Thanks Jason, that seems to work perfectly.

Now I'm going to learn why :-)

Sign in to reply to this post

Jason ByrnesWebAssist

OK, here's why:

your original code would only ever execute one time for the first item in the cart.

by adding a cart loop:
while (!$eCart1->EOF()) {
<do stuff>
$eCart1->MoveNext();
}


the code will execute once for each line item in the cart. the line:
$eCart1->MoveNext();

moves the reference to the next line item.

Sign in to reply to this post

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...