Jump to content

Updating text fields


adrian28uk

Recommended Posts

I am putting together a small test shopping cart. I have got the principles of how it works, however I have noticed that on a lot of carts you can update the quantities and press one update button to adjust the final qtys of all products before checking out.

 

What I need to do is put the id and qty by creating an array which I can do by submitting the form.

The first number in the array is the id of the product, and the second number is the new quantity, like so.

 

<?php

$quantities = array("789", "2", "790","3");

?>

 

This is the part where I get stuck.

I need to split the first two numbers from the array and then assign these to the mysql statement using a for each loop and so on.

 

I hope this makes some sort of sense.

 

 

 

 

 

 

 

Link to comment
Share on other sites

Do you mean something like this 234,235,236 could be the ids of the products. 2,3,4 are the updated quantities for these ids

 

$new_qty= array('234' => '2', '235' => '3', '236' => '4);

 

Then use a foreach loop to echo out the results?

I have managed to use foreach loop, the problem I had was extracting the id and qty so that I could put these in a MySQL query.

 

The answer to my problem is probably staring me in the face.

Link to comment
Share on other sites

instaid of using

 

<?php

$quantities = array("789", "2", "790","3");

?>

 

you can use

 

 

<?php

$quantities = array(array("789", "2"), array("790","3"));

?>

 

this will be easier to iterate through the array element using the nested loop

 

Rgds,

Sharad

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.