Hi,
I have a form where the user can add their qualifications but it is too long listed this way. I would like it changed to a drop down box where the user selects an area and then it displays the checkboxes related to that area.
Here is my code:
<?php
session_start();
if (@$auth != "yes")
{
header("Location: login.php");
exit();
}
include("Connections/conn.php");
include ("Connections/functions.php");
$sql = "SELECT firstName,lastName FROM member
WHERE loginName='$logname'";
$result = mysql_query($sql)
or die("Couldn't execute query 1.");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);
echo "<title>Aboriginal Natural Resources Management - Add your Qualificatons</title>";
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="file:///C|/Documents%20and%20Settings/Tammy%20Creaser/Local%20Settings/Temporary%20Internet%20Files/Content.IE5/0UV4PTKN/styles.css" type="text/css" />
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1344122-1";
urchinTracker();
</script>
<script language="JavaScript" type="text/javascript">
var d=new Date();
var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//Ensure correct for language. English is "January 1, 2004"
var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
</script>
<style type="text/css">
<!--
.style2 {color: #666666}
-->
</style>
</head>
<body bgcolor="#990100">
<table width="800" border="0" bgcolor="#ffffff" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#990100">
<td height="64" colspan="7"><img src="images/banner.gif" alt="Aboriginal NRM Board" width="800" height="150" /></td>
</tr>
<tr>
<td colspan="7" bgcolor="#003366"><img src="mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
</tr>
<tr bgcolor="#000000">
<td colspan="7" id="dateformat" height="25">
<script language="JavaScript" type="text/javascript">
document.write(TODAY); </script><div id="tagline">
"connecting Aboriginal communities to NRM activities" </div></td>
</tr>
<tr>
<td colspan="7" bgcolor="#ffffff"><img src="mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
</tr>
<tr>
<td width="165" valign="top" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="181" id="navigation">
<tr>
<td width="181"><?php include("menu.html"); ?>
</td>
</tr>
</table>
*
<div align="center"><br />
<a href="http://www.nht.gov.au/" target="_blank"><img src="images/nht.gif" alt="Natural Heritage Trust are sponsors of this project." width="88" height="150" border="0" /></a><br />
<br />
</div></td>
<td width="50"><img src="mm_spacer.gif" alt="" width="50" height="1" border="0" /><img src="mm_spacer.gif" alt="" width="305" height="1" border="0" /><br />
<br />
<br />
<table border="0" cellspacing="0" cellpadding="0" width="450">
<tr>
<?php
if (empty($_POST))
{
echo "<td class='pageName'>Add/Edit qualifications for $firstName $lastName</td></tr>";
echo "<tr><td><p class='bodytext'>";
echo "<form name=\"addqual\" action=\"addqual.php?id=".$_GET['id']."\" method=\"POST\">\n";
//GET LIST OF EXISTING training courses FROM DATABASE
$query1 = "SELECT training_id FROM membertraining WHERE memberloginName = '".$_GET['id']."'";
$result1 = mysql_query($query1) or die(mysql_error(). "Query: $query1");
$membertraining = array();
while ($row1 = mysql_fetch_assoc($result1))
{
$membertraining[] = $row1['training_id'];
}
//EXISTING LIST OF training IDS STORED IN $memberskills
$result = mysql_query("SELECT training.training_id,training.training_title FROM training LEFT JOIN training_hierarchy ON training_hierarchy.child = training.training_id WHERE training_hierarchy.parent IS NULL") or die(mysql_error());
//GET THE NAMES OF THE training AREAS
$training = array();
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_assoc($result))
{
$stitle = $row['training_title'];
$training[$stitle] = array();
//CREATE AN ARRAY FILLED WITH training AREAS AS KEYS
$query2 = "SELECT training.training_id,training.training_title FROM training LEFT JOIN training_hierarchy ON training_hierarchy.child = training.training_id WHERE training_hierarchy.parent = ".$row['training_id'];
$result2 = mysql_query($query2) or die (mysql_error()." Query: $query2");
if (mysql_num_rows($result2) > 0)
{
while ($row2 = mysql_fetch_assoc($result2))
{
$training[$stitle][] = array("id" => $row2['training_id'], "title" => $row2['training_title']);
//ADD THE training TO THEIR RESPECTIVE training AREAS AS AN ARRAY CONTAINING ID AND NAME
}
echo "<p>";
}
}
//dump($training);
foreach ($training as $key => $value)
{
if (empty($value))
continue; //IF NO training ARE AVAILABLE FOR A SKILL AREA SKIP THE SKILL AREA OUTPUT
else
{
echo "<table>\n";
echo "<tr><th colspan=\"4\">{$key}:</th>\n"; //OUTPUT training AREA TITLE
$counter = 0;
echo "<tr>\n";
foreach ($value as $value2)
{
echo "<td>".quote_smart($value2['title'])."</td><td><input type=\"checkbox\" value=\"{$value2['id']}\" name=\"training[]\""; //LIST training AND CHECKBOX
if (in_array($value2['id'],$membertraining))
echo "checked"; //CHECK THE CHECKBOX IF MEMBER HAS PREVIOUSLY ADDED training
echo "></td>\n";
$counter++;
if ($counter % 2 == 0) //LIMIT OUTPUT TO TWO training PER LINE
echo "</tr><tr>\n";
}
echo "</tr>";
echo "</table>";
}
}
echo "<p><input type=\"submit\" value=\"Add/Edit your qualification(s)\">";
echo "<input type=\"reset\" value=\"Reset Form\">";
}
echo "<input type=\"hidden\" name=\"user\" value=\"$logname\">";
echo "</p>";
echo "</form>";
}
else
{
//THIS SECTION IS EXACTLY THE SAME AS THE CODE FOR THE MEMBER REGION TABLE BUT USING THE SKILLS TABLE INSTEAD
$query1 = "DELETE FROM membertraining WHERE memberloginName='{$_POST['user']}'";
mysql_query($query1) or die(mysql_error()." Query: $query1");
if (!empty($_POST['training']))
{
foreach ($_POST['training'] as $trainingID){
$sql = "INSERT IGNORE INTO membertraining SET memberloginName='{$_POST['user']}', training_id='$trainingID'";
$ok = mysql_query($sql) or die(mysql_error(). "Query: $sql");
if (!$ok)
{
echo "<p>Error inserting training for member $trainingID: " . mysql_error() . '</p>';
}
}
}
echo "Qualifications added/edited. <a href=\"member_page.php?id={$_POST['id']}\">Back to member page</a>";
}
?>
</td>
</tr>
</table>