Hey people ....
I am trying to dynamically load data into combo boxes on selection of the first combo box items...
I am Using MySql and PHP .... i really just don't know what to do anymore ... please please please help me ...
PS - i am actually a C# Developer so web development is new to me
Here's my code, if you want it
<html>
<?php
//Creating a connection *******************************************************************************************
$connection = mysql_connect("localhost", "root", "*********");
if (!$connection)
{
die("Database connection failed : " .mysql_error() );
}
// ****************************************************************************************************************
//Selecting the four databases ************************************************************************************
$db_Sections = mysql_select_db("ncs_quote_system", $connection);
if (!$db_Sections)
{
die("Database selection failed : " .mysql_error() );
}
//*****************************************************************************************************************
?>
<head>
<script language="javascript">
function Select_Section()
{
var choice = document.formname.Sections.options[document.formname.Sections.selectedIndex].value;
if(choice == ['Description'])
{
document.all['Sub_Categories'].style.display = "none";
document.all['Categories'].style.display = "";
}
else if(choice == ['Description'])
{
document.all['Sub_Categories'].style.display = "";
document.all['Categories'].style.display = "none";
}
else
{
document.all['Sub_Categories'].style.display = "none";
document.all['Categories'].style.display = "none";
}
}
</script>
</head>
<body>
<form name="formname">
<?php
echo '<select name="Sections" onchange="Select_Section()">';
//Selecting table Sections *****************************************************************
$Sections = mysql_query("SELECT Description FROM sections", $connection);
if (!$Sections)
{
die("Database query failed : " .mysql_error() );
}
while ($RowSections = mysql_fetch_array($Sections))
{
echo '<option value='.$RowSections['Description'].'>'.$RowSections['Description'].'</option>';
}
echo '</select>';
?>
<br><br>
<div style="position: absolute; display: none" name="Categories_div" id="Categories_div">
<?php
echo '<select name="Categories">';
//Selecting table Sub_Categories ******************************************************************
$Sub_Categories = mysql_query("SELECT Description FROM subcategories, category_subcategory_link WHERE subcategories.id = category_subcategory_link.CategoryId ", $connection);
if (!$Sub_Categories)
{
die("Database query failed : " .mysql_error() );
}
while ($RowSubCategories = mysql_fetch_array($Sub_Categories))
{
echo '<option value='.$RowSubCategories['Description'].'>'.$RowSubCategories['Description'].'</option>';
}
echo '</select>';
?>
</div>
<div style="position: absolute; display: none" name="Sub_Categories_div" id="Sub_Categories_div">
<select name="Sub_Categories">
</div>
</form>
</body>
</html>
Cool ... please help me ...