Reply to Accessing Arrays in HTML

Your name:

Reply:


Posted by "Shaun" on 11/23/05 14:07

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация