Hello it's me again!
So I've managed to create 4 linked drop down boxes like:
Country : [===Country===|v|]
Client : [===Client===|v|]
Environment : [===Environment===|v|]
System: [===System===|v|]
And it's working fine with the codes written at the end of this post.
Next step is I wanted a Table to contain 2 columns with header "Product Name" and "Version" below the drop boxes on the same page.
When the user selects CLIENT, I want the Table to be filled with values based on the query:
SELECT pd.`Name`, vd.`Version`
FROM product pd, versiondetail vd, `client` cl, environment en, system sy
WHERE vd.`Product ID` = pd.`Product ID`
AND vd.`System ID` = sy.`System ID`
AND sy.`Environment ID` = en.`Environment ID`
AND en.`Client ID` = cl.`Client ID`
AND cl.`Client ID` = '[B]The ID of the selected client from the drop down box[/B]'
But when user selects the Environment, I want the Table to contain values only from the query:
SELECT pd.`Name`, vd.`Version`
FROM product pd, versiondetail vd, environment en, system sy
WHERE vd.`Product ID` = pd.`Product ID`
AND vd.`System ID` = sy.`System ID`
AND sy.`Environment ID` = en.`Environment ID`
AND en.`Environment ID`= '[B]The ID of the selected environment from the drop down box[/B]'
And finally if the user selects system, the table will only contain:
SELECT pd.`Name`, vd.`Version`
FROM product pd, versiondetail vd, system sy
WHERE vd.`Product ID` = pd.`Product ID`
AND vd.`System ID` = sy.`System ID`
AND sy.`System ID` = '[B]The ID of the selected system from the drop down box[/B]'
Question: How to achieve this?
Following are my current codes for the linked dropboxes:
country_dropdown.php:
<?
echo "<form name=sel>\n";
echo "Country : <font id=country><select>\n";
echo "<option value='0'>============</option> \n" ;
echo "</select></font>\n";
echo "Client : <font id=client><select>\n";
echo "<option value='0'>=== none ===</option> \n" ;
echo "</select></font>\n";
echo "Environment : <font id=environment><select>\n";
echo "<option value='0'>=== none ===</option> \n" ;
echo "</select></font>\n";
echo "System : <font id=system><select>\n";
echo "<option value='0'>=== none ===</option> \n" ;
echo "</select></font>\n";
?>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
try { return new XMLHttpRequest(); } catch(e) {}
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "country.php?data="+src+"&val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1");
req.send(null);
}
window.onLoad=dochange('country', -1);
</script>
country.php:
<?
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
include 'config.php';
include 'opendb.php';
if ($data=='country') {
echo "<select name='country'
onChange=\"dochange('client', this.value),
dochange('environment', this.value),
dochange('system', this.value)\">\n";
echo "<option value='0'>====State====</option>\n";
$result=mysql_query("SELECT c.`Country ID`, c.`Name`
FROM clientconfiguration.country c
ORDER BY `Name`")
or exit (mysql_error());
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value=\"$id\" >$name</option> \n" ;
}
} else if ($data=='client') {
echo "<select name='client'
onChange=\"dochange('environment', this.value),
dochange('system', this.value)\">\n";
echo "<option value='0'>====Client====</option>\n";
$result=mysql_query("SELECT cl.`Client ID`, cl.`Name`
FROM `client` cl, country co
WHERE cl.`Country ID` = co.`Country ID`
AND cl.`Country ID` = '$val'
ORDER BY cl.`Name`")
or exit(mysql_error());
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value=\"$id\" >$name</option> \n" ;
}
} else if ($data=='environment') {
echo "<select name='environment'
onChange=\"dochange('system', this.value)\">\n";
echo "<option value='0'>===Environment===</option>\n";
$result=mysql_query("SELECT en.`Environment ID`, env.`Type`
FROM `environment` en, `client` cl, `environmenttype` env
WHERE cl.`Client ID` = en.`Client ID`
AND env.`ID` = en.`Type`
AND en.`Client ID` = '$val'")
or exit(mysql_error());
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value=\"$id\" >$name</option> \n" ;
}
} else if ($data=='system') {
echo "<select name='system' >\n";
echo "<option value='0'>===System===</option>\n";
$result=mysql_query("SELECT sy.`System ID`, sy.`Label`
FROM system sy, environment en
WHERE en.`Environment ID` = sy.`Environment ID`
AND sy.`Environment ID` = '$val'")
or exit(mysql_error());
while(list($id, $name)=mysql_fetch_array($result)){
echo "<option value=\"$id\" >$name</option> \n" ;
}
}
echo "</select>\n";
?>