Dynamic Checkboxes
Posted: Thu Jun 26, 2003 12:57 am
Ok, I'm just about at the end of my wits with this one. I'm a php nub and simply cannot get this despite trying so many things. I have an options page. On that page, I'm querying the database to pull all the membergroups and put them on the page with a checkbox next to them. Up to this point, I'm fine. Now, what I need to do, is that if a checkbox is checked, it's going to pass that value into the membergroup table under the column cantitle. So, for example if I checked the box by administrator, in my table is would say:
membergroup | cantitle
Administrator | 1
And if they're not checked, they'd say 0 in the cantitle column...I just can't figure this out. The closest I got was actually getting it to put the value into there, but if you then unchecked it it wouldn't pass the 0 value, it would just skip the loop and not change the 1 value...I'd appreciate some help, I'm really lost. Here's what I've done:
That's calling up all the different membergroups, which works fine. And then this is in my post php:
I just don't get it. I'm really hoping someone can explain to me how to actually accomplish this.
Sincerely,
Methonis
membergroup | cantitle
Administrator | 1
And if they're not checked, they'd say 0 in the cantitle column...I just can't figure this out. The closest I got was actually getting it to put the value into there, but if you then unchecked it it wouldn't pass the 0 value, it would just skip the loop and not change the 1 value...I'd appreciate some help, I'm really lost. Here's what I've done:
Code: Select all
$request = mysql_query("SELECT * FROM `{$db_prefix}membergroups` WHERE ID_GROUP=1 OR ID_GROUP=8;") or database_error(__FILE__, __LINE__);
while ($row = mysql_fetch_array($request))
{
echo '
<tr>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><font size="2">' . $row['membergroup'] . '</font></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><input type="checkbox" name="chk~[' . $row['ID_GROUP'] . ']" value=". $row['cantitle'] . '/></td>
</tr>';
}
$request = mysql_query("SELECT * FROM `{$db_prefix}membergroups` WHERE `grouptype`=0 AND ID_GROUP>2 AND ID_GROUP!=8;") or database_error(__FILE__, __LINE__);
while ($row = mysql_fetch_array($request))
{
echo '
<tr>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><font size="2">' . $row['membergroup'] . '</font></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><input type="checkbox" name="chk~[' . $row['ID_GROUP'] . ']" value="'. $row['cantitle'] . '/></td>
</tr>';
}
echo '
<tr>
<td class="titlebg" bgcolor="' . $color['titlebg'] . '" colspan="3">
<a href="javascript:reqWin(''' . $scripturl . '?action=helpadmin;help=addctitle'')" class="help"><img src="' . $imagesdir . '/helptopics.gif" border="0" alt="' . $txt[119] . '" /></a>
<font size="2" class="text1" color="' . $color['titletext'] . '"><b>' . $txt['memtitle2'] . '</b></font>
</td>
</tr>';
$request = mysql_query("SELECT * FROM `{$db_prefix}membergroups` WHERE `grouptype`=1;") or database_error(__FILE__, __LINE__);
while ($row = mysql_fetch_array($request))
{
echo '
<tr>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><font size="2">' . $row['membergroup'] . '</font></td>
<td class="windowbg2" bgcolor="' . $color['windowbg2'] . '"><input type="checkbox" name="chk~[' . $row['ID_GROUP'] . ']" value="'. $row['cantitle'] . '/></td>
</tr>';
}Code: Select all
reset($_POST);
while(list($key, $val) = each($_POST)) {
if(substr($key, 0, 3) == "chk") {
$arKey = explode("~", $key);
$id = $arKey;
$request = mysql_query("UPDATE {$db_prefix}membergroups SET cantitle='$val' WHERE ID_GROUP='$id';") or database_error(__FILE__, __LINE__);
}
}Sincerely,
Methonis