/* insert code to connect to your database here */
/* get the checkbox labels */ $skills = get_checkbox_labels("const_skills");
/* create the html code for a formatted set of checkboxes */ $html_skills = make_checkbox_html($skills, 3, 400, "skills[]");
? >
Check off your web development skills: echo "$html_skills"; ? >
function get_checkbox_labels($table_name) {
/* make an array */ $arr = array();
/* construct the query */ $query = "SELECT * FROM $table_name";
/* execute the query */ $qid = mysql_query($query);
/* each row in the result set will be packaged as an object and put in an array */ while($row= mysql_fetch_object($qid)) { array_push($arr, $row); }
return $arr; }
/* Prints a nicely formatted table of checkbox choices.
$arr is an array of objects that contain the choices $num is the number of elements wide we display in the table $width is the value of the width parameter to the table tag $name is the name of the checkbox array $checked is an array of element names that should be checked */
function make_checkbox_html($arr, $num, $width, $name, $checked) {
/* create string to hold out html */ $str = "";
/* make it */ $str .= "
n"; $str .= "
n";
/* determine if we will have to close add a closing tr tag at the end of our table */ if (count($arr) % $num != 0) { $closingTR = true; }
$i = 1; if (isset($checked)) { /* if we passed in an array of the checkboxes we want to be displayed as checked */ foreach ($arr as $ele) { $str .= "