• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Using Check-boxes in Dreamweaver

Using Check-boxes in Dreamweaver
Hi All,
I’m making an admin section for a page where I want each record to have a checked Y/N box on it. I think I have this set up correct in the MYSQL database with the field type of “tinyint” and the default of 0. I have the default defined as 0 as I want all unchecked records to have no tick next to them. Am I defining the field type correctly in MYSQL?
I have built a recordset that calls the info from the DB. On the page I have a link from the “online_chk” checkbox to the recordset “det_checked” field. I must have something set up incorrectly here because the fields that I checked in the database never appear checked when I preview the page. Can anyone help? Here's what I have on the page so far.

<?php require_once('../Connections/GSM_mobile.php'); ?>
$maxRows_rsRemCheck = 10;
$pageNum_rsRemCheck = 0;
if (isset($_GET['pageNum_rsRemCheck'])) {
  $pageNum_rsRemCheck = $_GET['pageNum_rsRemCheck'];
$startRow_rsRemCheck = $pageNum_rsRemCheck * $maxRows_rsRemCheck;

mysql_select_db($database_GSM_mobile, $GSM_mobile);
$query_rsRemCheck = "SELECT details_table.det_user_id, details_table.det_checked, remote_details_table.rem_user_id, details_table.det_username, details_table.`date`, details_table.det_model_id, model_table.mod_model_id, remote_details_table.rem_if_other, model_table.mod_model_name, model_table.mod_type_id, type_table.type_type_id, type_table.type_type_name, category_table.cat_category_id, type_table.type_category_id FROM details_table, remote_details_table, model_table, type_table, category_table WHERE category_table.cat_category_id = type_table.type_category_id AND type_table.type_category_id = 1 AND  remote_details_table.rem_user_id = details_table.det_user_id   AND model_table.mod_type_id = type_table.type_type_id AND model_table.mod_model_id = details_table.det_model_id OR remote_details_table.rem_if_other <> NULL";
$query_limit_rsRemCheck = sprintf("%s LIMIT %d, %d", $query_rsRemCheck, $startRow_rsRemCheck, $maxRows_rsRemCheck);
$rsRemCheck = mysql_query($query_limit_rsRemCheck, $GSM_mobile) or die(mysql_error());
$row_rsRemCheck = mysql_fetch_assoc($rsRemCheck);

if (isset($_GET['totalRows_rsRemCheck'])) {
  $totalRows_rsRemCheck = $_GET['totalRows_rsRemCheck'];
} else {
  $all_rsRemCheck = mysql_query($query_rsRemCheck);
  $totalRows_rsRemCheck = mysql_num_rows($all_rsRemCheck);
$totalPages_rsRemCheck = ceil($totalRows_rsRemCheck/$maxRows_rsRemCheck)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {font-size: 10px}

<form id="form1" name="form1" method="post" action="">
  <p>All Remote Unlock Records:</p>
    <table width="690" border="1">
        <td width="182">Username:</td>
        <td width="210">Brand:</td>
        <td width="276">Model:</td>
        <td width="276">Checked (Y/N) </td>
      <?php do { ?>
        <td height="99"><a href="allremoteresults.php?User=<?php echo $row_rsRemCheck['det_user_id']; ?>"><?php echo $row_rsRemCheck['det_username']; ?></a></td>
        <td><?php echo $row_rsRemCheck['type_type_name']; ?></td>
        <td><label>if (<?php echo $row_rsRemCheck['det_model_id']; ?> != ""){echo <?php echo $row_rsRemCheck['mod_model_name']; ?>} else {echo <?php echo $row_rsRemCheck['det_model_id']; ?>} </label></td>
        <td><div align="center">
          <input <?php if (!(strcmp($row_rsRemCheck['det_checked'],0))) {echo "checked=\"checked\"";} ?> type="checkbox" name="checkbox" value="online_chk" />
        <?php } while ($row_rsRemCheck = mysql_fetch_assoc($rsRemCheck)); ?>

  • 3
  • 2
1 Solution
Jason C. LevineNo oneCommented:
Hi Derek,

>> Am I defining the field type correctly in MYSQL?

Sort of.  Using tinyints will work but I actually prefer to set these fields to ENUM('Y','N') not null and avoid making DW write strcmp statements.  Bonus...the DW insert and update record wizards default checkboxes to "checkbox y/n"

Also, DW gets squirrelly about dynamic assignments.  Try setting the checkbox values to:

 <input name="yourcolumnname" type="checkbox" id="yourcolumnname" value="Y" />

before assigning it the dynamic value.
dereksheahanAuthor Commented:
Hi Jason,
Thanks I have that changed and it works. The code seems like its repeating itself though. Am I not saying the same thing twice here?
<input <?php if (!(strcmp($row_rsRemCheck['det_checked'],"Y"))) {echo "checked=\"checked\"";} ?> name="been_checked" type="checkbox" id="<?php echo $row_rsRemCheck['det_checked']; ?>"  value="Y" />

Also, I want the checkboxes on one of the admin pages to be read only. I know how to do this for text boxes (readonly="readonly") but the same code won't work for a check-box. Is this easy to do?
Jason C. LevineNo oneCommented:
Little bit of repetition in your code, see below.

<input <?php if (!(strcmp($row_rsRemCheck['det_checked'],"Y"))) {echo "checked=\"checked\"";} ?> name="been_checked" type="checkbox" id="been_checked"  value="Y" />

>> Is this easy to do?


Oh, you want the code, do you?

<input disabled blah blah blah />
dereksheahanAuthor Commented:
Legend. Thanks a mil
Jason C. LevineNo oneCommented:
Shucks, I'm blushing here...

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now