我想在我的php中下载。
这意味着,我将有2个下拉列表。 第一个下拉列表:小吃和小吃,饮料,洗浴用品 第二个下拉列表:基于第一个下拉列表中的类别的不同子类别。
我想得到的结果是什么 当我选择First first下拉列表,并选择snack& tibits时,在第二个下拉列表中,它将仅显示与snack& amp;相关的子类别。其他的2,等等,等等。
我试了一下,但是当我尝试检索第二个下拉列表时,它总是空白的。 有人能告诉我如何改进我的代码?
谢谢
<td width="175">Category:</td>
<td width="405">
<label>
<select name="category_sel" id="category_sel" required="required" >
<?php
do {
?>
<option value="<?php echo $row_sup_cat['category']?>"><?php echo $row_sup_cat['category']?></option>
<?php
} while ($row_sup_cat = mysql_fetch_assoc($sup_cat));
$rows = mysql_num_rows($sup_cat);
if($rows > 0) {
mysql_data_seek($sup_cat, 0);
$row_sup_cat = mysql_fetch_assoc($sup_cat);
}
?>
</select>
</label>
</tr>
<tr>
<td>Subcategory:</td>
<td>
<select name="subcatgory" id="subcatgory" required="required" >
<?php
do {
?>
<option value="<?php echo $row_sup_subcat['subcategory']?>"><?php echo $row_sup_subcat['subcategory']?></option>
<?php
} while ($row_sup_subcat = mysql_fetch_assoc($sup_subcat));
$rows = mysql_num_rows($sup_subcat);
if($rows > 0) {
mysql_data_seek($sup_subcat, 0);
$row_sup_subcat = mysql_fetch_assoc($sup_subcat);
}
?>
</select>
</td>
</tr>
...
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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_MyDatabase, $MyDatabase);
$query_sup_cat = "SELECT DISTINCT category FROM supermarket";
$sup_cat = mysql_query($query_sup_cat, $MyDatabase) or die(mysql_error());
$row_sup_cat = mysql_fetch_assoc($sup_cat);
$totalRows_sup_cat = mysql_num_rows($sup_cat);
$query_sup_cat = "SELECT DISTINCT category FROM supermarket";
$sup_cat = mysql_query($query_sup_cat, $MyDatabase) or die(mysql_error());
$row_sup_cat = mysql_fetch_assoc($sup_cat);
$totalRows_sup_cat = mysql_num_rows($sup_cat);
$colname_sup_subcat = "-1";
if (isset($_POST['category_sel'])) {
$colname_sup_subcat = $_POST['category_sel'];
}
mysql_select_db($database_MyDatabase, $MyDatabase);
$query_sup_subcat = sprintf("SELECT subcategory FROM supermarket WHERE subcategory = %s", GetSQLValueString($colname_sup_subcat, "text"));
$sup_subcat = mysql_query($query_sup_subcat, $MyDatabase) or die(mysql_error());
$row_sup_subcat = mysql_fetch_assoc($sup_subcat);
$totalRows_sup_subcat = mysql_num_rows($sup_subcat);
?>