Forum Moderators: coopster

Message Too Old, No Replies

Submit page a d working with $_post data

arrays, submit, check boxes, $_post

         

sforshey

1:38 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



I am working with data that I pull from one of tables in my data base and format it into tables for ever entry on my webpage. In each table I place a check box called review (see code below):

.......
print"<td valign=center bgcolor=\"#99CCFF\"> <div align=center><input type=checkbox name=review[] value=$search>&nbsp;Review</div></td>\n";
print"</tr>\n";.......

When I click on my submit button to go to the next page to review the entries that were selected by checking the review check box all I get is this:

Code:
echo "<pre>";
print_r($_POST); // or $HTTP_POST_VARS if you have older PHP
echo "</pre>";

Output:
Array
(
[review] => Array
(
[1] => GMWA.EXE
[5] => GMWA202.PBD
[6] => GMWA203.PBD
[10] => PBO7360.DLL
[11] => PBRTC60.DLL
)

[view] => Review
)

How would I work with the values in the array. I have tried everything that I know, but I don't get the correct variables.

Thanks for any help that anyone can provide.

scumm_bar2

4:34 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



There are gaps in the array where a checkbox has not been checked on the previous page. Does that matter, or are you just looking to loop right through the array?

If you need the array to match other data on a one-to-one basis, ie. taking into account the unchecked boxes, then one solution is to have an ID associated with each checkbox.

You can name the checkboxes as follows:

<table>
<input type="hidden" name="IDSet[]" value="1">
<input type="checkbox" name="checkbox1" value="$search">
</table>

<table>
<input type="hidden" name="IDSet[]" value="2">
<input type="checkbox" name="checkbox2" value="$search">

...
...

<table>
<input type="hidden" name="IDSet[]" value="53">
<input type="checkbox" name="checkbox53" value="$search">
</table>

then in your php:

<?
$countLoop = count($IDSet);
for ($i = 0; $i < $countLoop; $i++)
{
// Get ID
$id = $IDSet[$i];

// Get checkbox value associated with ID
$checkboxName = 'checkbox'.$id;
$checkboxValue = $$checkboxName;

// Do other stuff
}
?>

sforshey

5:24 pm on Feb 13, 2004 (gmt 0)

10+ Year Member



Thanks for the tip. I will give that a try. Also, there will be gaps in my selections. A user will basically check the box for entries that they would want to review in more detail. So It could range from 1 to a 100+ selections made.