Jump to content

PHP array - keeping results in line with each other


richrock

Recommended Posts

Hi,

 

I've set up a form to process an array of items, and I can get the form to return, save, etc.  But I noticed a small problem - when submitting a checkbox, the array sets it to [0], and not it's position in the form list.

 

Here's the source for the form:

 

// Create the table full of sale data
	while ($row = mysql_fetch_assoc($rSaleList)) {

		echo "<tr>\n";
		echo "<td>\n";
		echo "<input type='text' name='id[]' size='7' value='".$row['id']."' READONLY />";
		echo "</td>\n";
            echo "<td>\n";
		echo "<input type='text' name='sale_num[]' size='2' maxlength='1'  value='".$row['salenum']."' />";
		echo "</td>\n";
		echo "<td width='140'>\n";
		echo "<input type='text' name='day[]' value='".$row['day']."' size='1' maxlength='2' /> - <input type='text' name='month[]' value='".$row['month']."' size='1' maxlength='2' /> - <input type='text' name='year[]' value='".$row['year']."' size='3' maxlength='4' />";
		echo "</td>\n";			
		echo "<td width='50'>\n";
		if ($row['active'] == 1) {
		echo "<input type='checkbox' name='published[]' value='1' ";
		echo "checked='yes'";
		echo " />";
		} elseif ($row['active'] == 0) {
		echo "<input type='checkbox' name='published[]' value='0' ";
		echo "/>";
		}
		echo "</td>\n";

		echo "</tr>\n";

	}

 

And here's the POST output after submitting, with the third item (out of 6) checked:

 

POST: Array
(
    [id] => Array
        (
            [0] => 1012
            [1] => 1000
            [2] => 4
            [3] => 3
            [4] => 2
            [5] => 1
        )

    [sale_num] => Array
        (
            [0] => 2
            [1] => 1
            [2] => 1
            [3] => 1
            [4] => 1
            [5] => 1
        )

    [day] => Array
        (
            [0] => 11
            [1] => 11
            [2] => 00
            [3] => 00
            [4] => 00
            [5] => 00
        )

    [month] => Array
        (
            [0] => 03
            [1] => 03
            [2] => 00
            [3] => 00
            [4] => 00
            [5] => 00
        )

    [year] => Array
        (
            [0] => 2009
            [1] => 2009
            [2] => 0000
            [3] => 0000
            [4] => 0000
            [5] => 0000
        )

    [published] => Array
        (
            [0] => 0
        )

    [updateSale] => Update Sales

 

So how would I get [published] to show [4] => 0 ? (or 1, depending on it's selection)...

 

TIA

Archived

This topic is now archived and is closed to further replies.

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