Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 09:50:55 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: dynamic drop down menu  (Read 3997 times)

kevstero

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 16
    • View Profile
    • Donate to Member
IDEA: dynamic drop down menu
« on: June 26, 2008, 01:45:36 PM »
Hi. Here's my problem.

I have two tables. One is a main category table and the other is a subcategory table.

The main category table has the fields (catID and catName)

The Subcategory table has the fields (catId, SubId and SubName)

The two are related via the catId field..

I can't figure out how to dynamically load the second drop down menu from the choice made in the first drop down menu.. If anybody can point out whats wrong or develop something similar, it would be nice... Thanks.


<?php require_once('Connections/antiques.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

mysql_select_db($database_antiques, $antiques);
$query_Recordset1 = "SELECT * FROM itemmastercategory";
$Recordset1 = mysql_query($query_Recordset1, $antiques) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_antiques, $antiques);
$query_Recordset2 = "SELECT * FROM itemmastercategory";
$Recordset2 = mysql_query($query_Recordset2, $antiques) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...ml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="select" id="select">
<option value="">Choose Antique Category</option>
<?php
do {
?>
<option value="<?php echo $row_Recordset1['CatId']?>"><?php echo $row_Recordset1['CatName']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label>
<label>
<select name="select2" id="select2">
<option value="">Choose Antique Sub Category</option>
<?php
do {
?><option value="<?php echo $row_Recordset2['SubId']?>"><?php echo $row_Recordset2['SubName']?></option>
<?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows > 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?>
</select>
</label>
</form>
</body>
</html>
<?php
mysql_free_result($Recordset1);

mysql_free_result($Recordset2);
?>