Accessing Arrays in HTML
| From: | Shaun | Date: | Wed, 23 Nov 2005 12:07:00 +0000 |
| Subject: | Accessing Arrays in HTML | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-226341@lists.php.net to get a copy of this message | ||
Hi,
I am trying to create a form on my page. The idea is that for each project
people can select whether they are allocated for scheduling, non_scheduling
or both. Here is an example of my form:
<tr>
<td><input name="project[44][Scheduling]" type="checkbox"
value="44"></td>
<td><input name="project[44][Non_Scheduling]" type="checkbox"
value="44"><td>
<td>Project 1</td>
</tr>
<tr>
<td><input name="project[25][Scheduling]" type="checkbox"
value="25"><td>
<td><input name="project[25][Non_Scheduling]" type="checkbox"
value="25"></td>
<td>Project 2</td>
</tr>
I am trying to access the arrays in the HTML as follows:
if (is_array($_POST['project'])){
$fields='';
$values='';
foreach ($_POST['project'] as $project_id => $value) {
$fields[] = $project_id;
$values[] = $value;
}
$i = 0;
$num_elements = count($fields);
while($i < $num_elements){
if(($values[$i]) != 0){
echo '<br />$i = '.$i.'<br />';
print_r($fields);
$query = ("INSERT INTO Allocations (
User_ID,
Project_ID,
Scheduling,
Non_Scheduling
) VALUES (
'".$user_id."',
'".$fields[$i]."',
'".$fields[$i][0]."',
'".$fields[$i][1]."',
)");
echo $query.'<br />';
}
$i++;
}
}
However I can't access the 'Scheduling / 'Non_Scheduling' part. Can anyone
see where I am going wrong here?
Thanks for your advice