Jump to content

SQL Update with Array Values


NickG21

Recommended Posts

Hey guys,

    I was wondering if someone could point me in the right direction here.  Basically im trying to be able to update multiple rows of a database depending on the ID value posted in the variable.  Here is what I mean.

 

I loop through a query that retrieves all the products in the respect order and create a select box for each like this;

	<?php	$OrProds = mysql_query("SELECT * from tblOrderProduct Inner Join tblProduct on tblOrderProduct.OpID = tblProduct.PrID Inner Join tblOrder on tblOrderProduct.OpOrID = tblOrder.OrID where OpOrID ='" . $OrID . "'");

				while($rsOrProds = mysql_fetch_array($OrProds)){ ?>
					<tr>
						<td>Product ID:</td><td>Product Name:</td><td>Price:</td><td>Quantity:</td><td>Total:</td><td>Maker:</td><td>Image</td>
					</tr>
					<tr>
						<td><?php echo $rsOrProds['OpID']; ?></td><td><?php echo $rsOrProds['PrName']; ?></td><td><?php echo '$' . $rsOrProds['OpPrPrice']; ?></td><td align="center"><?php echo $rsOrProds['OpCartPrQty']; ?></td><td><?php echo '$' . ($rsOrProds['OpCartPrQty'] * $rsOrProds['OpPrPrice']); ?></td><td><?php echo $rsOrProds['OpPrMaker']; ?></td><td><img src="<?php echo $rsOrProds['PrImage']; ?>" height="40" width="40"></td>
					</tr>

				<? 
				$total = $total + ($rsOrProds['PrPrice'] * $rsOrProds['OpCartPrQty']);

					?>
					<tr>
						<td colspan="3">Product Status</td>
Create select box using OpID		<td><select name="OpStatus[<?php echo $rsOrProds['OpID']; ?>]">
							<option value=""<?php if ($rsOrProds['OpStatus'] == ""){?> selected="selected" <?php } ?>></option>
							<option value="New"<?php if ($rsOrProds['OpStatus'] == "New"){?> selected="selected" <?php }?>>New</option>
							<option value="Pending"<?php if ($rsOrProds['OpStatus'] == "Pending"){?> selected="selected" <?php } ?>>Pending</option>
							<option value="Waiting Tracking"<?php if ($rsOrProds['OpStatus'] == "Waiting Tracking"){?> selected="selected" <?php } ?>>Waiting Tracking</option>
							<option value="Shipped"<?php if ($rsOrProds['OpStatus'] == "Shipped"){?> selected="selected" <?php } ?>>Shipped</option>
							<option value="Complete"<?php if ($rsOrProds['OpStatus'] == "Complete"){?> selected="selected" <?php } ?>>Complete</option>
						</td>
					<?php } ?>

 

What I want to do is be able to update the row depending on the OpID that is found in the select box submitted.  The values are being submitted correctly as i've printed all $_POST variables to the screen and received these as the array values;

[OpStatus] => Array

        (

            [6] => Waiting Tracking

            [310] => Shipped

        )

 

I am just unsure of what steps to take to update the database?  Any suggestions would be great, this is what my thought process is;

 

foreach value in OpStatus

      update tblOrderProduct set OpStatus = new status Where OpID = OpID associated with the array?

 

thanks in advance to any help you can give me?!

 

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.