Using Check-boxes in Dreamweaver

Posted on 2006-05-14
Last Modified: 2010-04-03
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" "">
<html xmlns="">
<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)); ?>

Question by:dereksheahan
    LVL 70

    Expert Comment

    by:Jason C. Levine
    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.

    Author Comment

    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?
    LVL 70

    Accepted Solution

    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 />

    Author Comment

    Legend. Thanks a mil
    LVL 70

    Expert Comment

    by:Jason C. Levine
    Shucks, I'm blushing here...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Create Mobile App Prototypes with Adobe XD

    This is a project-based course: we go through all the steps of creating a prototype from start to finish, using all the tools and features currently available in Adobe XD. You can complete the course in less than a day, plus all project files and fonts are included.

    For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now