How can I add a third drop down to this code. I have not been able to figure it out. Thanks!!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="jqueryui/js/jquery-ui-1.8.15.custom.min.js"></script>
<script type="text/javascript" src="jqueryui/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("select#category").change(function(){
var id = $("select#category option:selected").attr('value');
$.post("select_type.php", {id:id}, function(data){
$("select#type").html(data);
});
});
});
</script>
</head>
<body>
<?php
include("select.class.php");
?>
<form id="select_form">
Choose a category:<br />
<select id="category">
<?php
echo $opt->ShowCategory();
?>
</select>
<br /><br />
choose a type:<br />
<select id="type">
<option value="0">choose...</option>
</select>
<br /><br />
choose third drop down: <br />
<select id="third_table">
<option value="0">choose...</option>
</select>
<br /><br />
<input type="submit" value="confirm" />
</form>
<div id="result"></div>
</body>
</html>
*************************************************************************************************
This is the class, I already added the code that queries the third database table
<?php
class SelectList
{
protected $conn;
public function __construct()
{
$this->DbConnect();
}
protected function DbConnect()
{
include "db_config.php";
$this->conn = mysql_connect($host,$user,$password) OR die("Unable to connect to the database");
mysql_select_db($db,$this->conn) OR die("can not select the database $db");
return TRUE;
}
public function ShowCategory()
{
$sql = "SELECT * FROM category";
$res = mysql_query($sql,$this->conn);
$category = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$category .= '<option value="' . $row['id_cat'] . '">' . $row['name'] . '</option>';
}
return $category;
}
public function ShowType()
{
$sql = "SELECT * FROM type WHERE id_cat=$_POST[id]";
$res = mysql_query($sql,$this->conn);
$type = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$type .= '<option value="' . $row['id_type'] . '">' . $row['name'] . '</option>';
}
return $type;
}
public function ShowThird()
{
$sql = "SELECT * FROM thirdtable WHERE id_type=$_POST[id2]";
$res = mysql_query($sql,$this->conn);
$third = '<option value="0">choose...</option>';
while($row = mysql_fetch_array($res))
{
$third .= '<option value="' . $row['id_third'] . '">' . $row['name'] . '</option>';
}
}
}
$opt = new SelectList();
?>
*************************************************************************************************
select_type.php
<?php
include "select.class.php";
echo $opt->ShowType();
?>