This may be straightforward, but I have not done it before and am having trouble figuring it out. Essentially, there are Workgroups (comprised of people) and Projects (which belong to Workgroups). Both are maintained in the database. When I add a person to a Workgroup, I also want to be able to add him to the Projects within that Workgroup. Step 1 then is to look up all the Projects within that Workgroup and provide a check box for each. As we're adding the person, we already know the Workgroup, so it's assigned $wg. Here's the code in the form:
Get a list of the Projects for this Workgroup
$sql_projects="
SELECT p.project_id, p.project_name
FROM project as p, workgroup as w
WHERE w.workgroup_id=$wg
AND p.workgroup_id=w.workgroup_id";
if ($result_projects=mysql_query($sql_projects)) {
$n=1;
while ($row_projects=mysql_fetch_array($result_projects)) {
echo "<input type=\"Checkbox\" name=\"w$n\" value=\"1\""> $row_projects[project_name]<br>";
$n++;
}
}
This works well, and we end up with check boxes named w1, w2, w3, etc.
Then, when submitting this to the database, I need to run through the list of Projects again and see if any were checked. I'm doing that like this:
And add the person to any projects that are checked
Get a list of the Projects for this Workgroup
$sql_projects="
SELECT p.project_id, p.project_name
FROM project as p, workgroup as w
WHERE w.workgroup_id=$wg
AND p.workgroup_id=w.workgroup_id";
if ($result_projects=mysql_query($sql_projects)) {
$n=1;
while ($row_projects=mysql_fetch_array($result_projects)) {
$prid=$row_projects['project_id'];
if (@$w$n) {
$add2project=(mysql_query("
INSERT INTO person2project (person_id, project_id)
VALUES ('$personID', '$prid')"));
}
$n++;
}
}
This is not working, however, as I get a parse error on the line that says 'if (@$w$n) {'. I've tried 'if (@$w$n == 1) {' also and get the same error.
Can someone help me figure this out please?
Thanks.