Jump to content

get values for a 2-dimension array


ivytony

Recommended Posts

The html page includes this below info that I want to get:

 

<form name="bulk_moderate" action="arraypro.php?action=bulkmod" method="post">
<table cellpadding="1" cellspacing="2" border="0">
<tr>
  <th>Transaction Date </th>
  <th>Order # </th>
  <th><center>
    Sale Amount(no $)
  </center>	    </th></tr>

	<tr bgcolor="#FFFFFF">	
	<td>Mar 8, 2008 07:45:34 pm</td>

	<td>
	<input name="order[501]" type="text" id="order-501" value="" maxlength="50" />	
	<input name="customerID[501]" type="hidden" id="customerID-501" value="2%" maxlength="50" />		  </td>
	<td><input name="sale[501]" type="text" id="sale-501" value="0.00" maxlength="15" /></td>
</tr>	
	<tr bgcolor="#f2f2f2">	
	<td>Mar 8, 2008 08:30:21 pm</td>
	<td>
	<input name="order[502]" type="text" id="order-502" value="" maxlength="50" />	
	<input name="customerID[502]" type="hidden" id="customerID-502" value="4%" maxlength="50" />		  </td>
	<td><input name="sale[502]" type="text" id="sale-502" value="0.00" maxlength="15" /></td>
</tr>	
	<tr bgcolor="#FFFFFF">	
	<td>Mar 8, 2008 08:33:45 pm</td>
	<td>

	<input name="order[503]" type="text" id="order-503" value="" maxlength="50" />	
	<input name="customerID[503]" type="hidden" id="customerID-503" value="4%" maxlength="50" />		  </td>
	<td><input name="sale[503]" type="text" id="sale-503" value="0.00" maxlength="15" /></td>
</tr>	</table></form>

 

This form is to update orders in bulk mode (update a bunch of orders). So  I need to get the values of input fields for order[iNT] (e.g. order[503]), sale[iNT] and customerID[iNT]. The INT number in the bracket [] will be used to find the record in database and update the order, sale and customerID columns.

 

I tried to write this code:

 

<?php
if ($_GET['action'] == "bulkmod") {
	if(!empty($_POST['submit'])) {
		$order = array();
		$sale = array();
		$customerID = array();
		foreach ($_POST["order"] as $k => $v) {
			$order[intval($k)] = $v;
		}
			foreach ($_POST["sale"] as $k => $v){
				$sale[intval($k)] = $v;
			}

			foreach($_POST["customerID"] as $k => $v){
				$customerID[intval($k)] = $v;
				}


		echo count($order).'<br />';
		echo count($sale) .'<br />';
		echo count($customerID).'<br />';


		foreach($order as $key => $value) {

			$db->query('UPDATE `' . table_orders . '` SET `order_number` = "$value" WHERE `order_id` = "'.$key.'"');
			}


?>

 

Although it works, I am wondering if I can use one two-dimensional array that has columns 'order', 'sale', and 'customerID', $key as row pointer.

 

thanks!

Link to comment
Share on other sites

change your form to

	<input name="orders[501][order]" type="text" id="order-501" value="" maxlength="50" />	
	<input name="orders[501][customerID]" type="hidden" id="customerID-501" value="2%" maxlength="50" />		  </td>
	<td><input name="orders[501][sale]" type="text" id="sale-501" value="0.00" maxlength="15" /></td>
</tr>	

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.