Boolean value - Checkbox - join table

Hi all,
I wonder if you guys can help me. I’m creating a module information system which allows a student to view all the compulsory and optional modules that can be studied within a course. Once a module has been created it then can be associated with a course.

In the admin section I have created a page which allows you to create a module, I’m in the process of creating the course page where it allows the admin to create a course and select the modules the course comprises of. I would like the admin to have the ability to select if the module is compulsory or optional.

Here is an interface design for the courses page.
http://www.2shared.com/photo/mw168s7U/Courses_-_Interface.html

At the moment this is what my table structure is (ERD). http://www.2shared.com/photo/KyCPT4gl/ERD_Model.html

In the join table (coursemodule) I have four attributes (ID, courseID, moduleID, iscore). When a new course has been created and modules are selected it sends the ID of the course and module into the join table.
I would like to populate a second checkbox which would appear next to the module which when both check boxes are checked it would send a ‘1’ to the ‘iscore’ attribute and if it is unchecked but the first checkbox is selected it would send ‘0’ to the ‘iscore’ attribute.

I have set the ‘iscore’ field to Boolean but am struggling what piece of code I would need to write in order to send these values in a check box. I wonder if you guys could help. Thanks

Here is the code within the courses page:
//

Course Title A value is required.
Course Modules <?php //This block creates a list of modules from the modules table $category_list = ""; // $iscore = ""; $sql2 = "SELECT * FROM modules"; $result2 = mysql_query($sql2) or die(mysql_error()); $catCount = mysql_num_rows($result2); //count the output amount //echo 'No of categories: '.$catCount.'
'; if($catCount > 0){ while($row2 = mysql_fetch_array($result2)){ $isCore = false; $moduleID = $row2["moduleID"]; $catName = $row2["moduleTitle"]; // $category_list .= ' '.$catName.' '; $category_list .= '   '.$catName.'
'; } } else { $product_list = "Unable to create category list"; } echo $category_list; ?>
                </td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>
                <input type="hidden" name="dbtable" value="courses" />
                </td>
                
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><div align="right">
                  <input type="submit" value="Add Course" />
                </div></td>
              </tr>
      </table></form>

// Here is the php code in the course_add.php file

Uploading...

Uploading...

<?php require_once('../../Connections/module_system.php'); echo '
modules: '; foreach($_POST['module'] as $cats) { echo $cats.', '; } echo '

Uploading course details to the database...

';

$courseTitle=$_POST[‘courseTitle’];

$query = "INSERT INTO courses (courseTitle) VALUES ('".$courseTitle."')";

$result = mysql_query($query);

$pid = mysql_insert_id();

//echo pull out course ID from last record inserted to enter into course module table

echo ‘ID of last inserted Course is = ‘.$pid.’
’;

//SQL for modulecourses
echo ‘

Uploading course module information to the database…

’;
$cats_upload = “”;
foreach($_POST[‘module’] as $cats)
{
$isCore=$_POST[‘core’];

echo $pid.’ - ‘.$cats.’ - ‘.$isCore.’
’;
$query2 = “INSERT INTO coursemodule (courseID, moduleID, iscore) VALUES (’”.$pid."’,’".$cats."’,’".$isCore."’)";
$result2 = mysql_query($query2);
if ($result2) {
$cats_upload = $cats_upload + mysql_affected_rows(); //
} else {
echo “an error has occurred uploading to the coursemodule table.
”;
}
}
echo 'Number of Modules Uploaded: '.$cats_upload;
?>

In the bit where you generate the checkboxes (they already appear in the HTML) try adding an if to check if the value is set to 0 or 1. Example checkbox code

Unchecked

[php][/php]

Checked

[php][/php]

Of course you’ll need to include your other attributes in the HTML, this is just to show what a checkbox looks like unchecked vs checked.

Sponsor our Newsletter | Privacy Policy | Terms of Service