i have been trying to do this for awhile, but can't get it to work right. any suggestions would be great.
i have 3 tables, master_list, subject, and subscription
master_list = person_id, first, last, email, phone, addy
subject = subject_id, description
subscription = subscription_id, person_id, subject_id
i am using this to manage mailing lists.
when i sign a user up, i enter their details, and then check the boxes i subscripe them to. It generates the checkboxes from the subject table. No problem, I enter the users details, and it enters them into the correct tables.
Now i have anohter page which prints out each username and email and then checkboxes for each subject, checked if they are subscribed, unchecked if they are not.
i want to be able to switch the checks around (remember, it prints out every username) and then hit update, and it will update the subscription table with the new info. this is where i am running into problems.
here is some of my code..(and i know a lot of it is poorly coded, i'm trying to do this fairly quickly)
viewlist.php
echo "</tr>\n";
echo "<tr bgcolor =\"#CCCCCF\"><td nowrap>\n";
echo "<font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#333333\">" . $row ['last'] . "</font></td><td nowrap><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#333333\">" . $row['first'] . "</font></td><td nowrap><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#333333\"><a href =\"mailto: " .$row['email'] . "\">" . $row ['email'] . "</a</font></td>\n";
++$counterx;
echo "<input type = \"hidden\" name=\"email[$counterx][$counterx]\" value =". $row['person_id'] . ">";
// echo "<input type = \"hidden\" name=\"email[$counterx]\" value =". $row['person_id'] . ">";
$result = mysql_query("select from subject order by description");
$myrow = mysql_fetch_array($result);
$subnum = mysql_num_rows($result);
$result2 = mysql_query("select from master_list");
$myrow2 = mysql_fetch_array($result2);
do {
$subject_id = $myrow["subject_id"];
$person_id = $row["person_id"];
// find all records that have already been checked
$checkedresults = mysql_query("Select * from subscription where person_id=$person_id and subject_id=$subject_id");
$num = mysql_num_rows($checkedresults);
// if a record has already been checked append "checked" to the end of the input tag in the html
if ($num==1) {
$subject_id = str_replace($subject_id, "$subject_id checked", $subject_id);
}
// printf ("<td><input type=\"checkbox\" name=\"skills[]\" value=%s>%s</input></tr>", $subject_id, $myrow['description'] );
++$countery;
if ($countery > $subnum)
{
$countery = 1;
}
printf ("<td nowrap><center><input type=\"checkbox\" name=\"skills[$countery][$counterx]\" value=%s>%s</input></center></td>\n", $subject_id, $myrow['blah'] );
} while ($myrow = mysql_fetch_array($result));
echo "</tr><br>";
}
echo "<input type = \"hidden\" name = first value = $counterx>";
echo "<input type = \"hidden\" name = second value = $countery>";
?>
and then updatelist.php is the php that would update the database and this is where i am really running into problems...maybe something like this
$sql = "DELETE FROM subscription WHERE person_id = '${"email" . $first}[$first]'";
$sql2 = "INSERT INTO subscription (person_id, subject_id) VALUES ('${"email" . $first}[$first]', '${"skills" . $second}[$second]')";
$sql3 = "DELETE FROM subscription WHERE person_id = 0";
$sql4 = "DELETE FROM subscription WHERE subject_id = 0";
// $result = mysql_query($sql,$linkID);
// $result2 = mysql_query($sql2,$linkID);
// $result3 = mysql_query($sql3, $linkID);
// $result4 = mysql_query($sql4, $linkID);