有没有办法继续传递一个值,在第一个(或更早)下拉选择表单中提交到后续处理代码/文件 - 在第一个处理文件之后?
这就是我想要做的:我为鞋类创建了一个数据库(尺寸、类型、样式表),然后我创建了一个名为“syle_in_size”的查找表,它的大小与样式相关。这个想法是让查询从这个表开始,以便一切都基于用户在搜索开始时选择的 SIZE。从那里,将确定具体的鞋类(尺寸、款式和类型)。
所以我想出了从一个下拉/选项表传递到另一个的代码(我知道,不同的页面***我已经看到建议和页面在一个页面中完成所有操作,但我想连续执行 -部分是作为一个设计元素,也因为我不知道 javascript,因为我几个月前才开始编程——一次只使用一种语言)。
这是我所拥有的:
尺寸表
+--------+------+
| sizeid | size |
+--------+------+
| 7.0 | 7.0 |
| 7.5 | 7.5 |
| 9.0 | 9.0 |
| 9.5 | 9.5 |
| 11.0 | 11.0 |
+--------+------+
类型表
+--------+---------+
| typeid | type |
+--------+---------+
| 1 | Shoes |
| 2 | Boots |
| 3 | Sandals |
+--------+---------+
风格表
+---------+--------+------------+
| styleid | typeid | style |
+---------+--------+------------+
| 1 | 1 | Athletic |
| 2 | 1 | Lace-up |
| 3 | 1 | Loafers |
| 4 | 1 | Moccasins |
| 5 | 2 | Combat |
| 6 | 2 | Hiking |
| 7 | 2 | Riding |
| 8 | 3 | Flip Flops |
| 9 | 3 | Slide |
+---------+--------+------------+
STYLE_IN_SIZE 表
+---------------+--------+---------+
| sizeinstyleid | sizeid | styleid |
+---------------+--------+---------+
| 1 | 7.0 | 1 |
| 2 | 7.5 | 1 |
| 3 | 11.0 | 1 |
| 4 | 7.5 | 2 |
| 5 | 9.0 | 2 |
| 6 | 7.5 | 3 |
| 7 | 11.0 | 3 |
| 8 | 7.0 | 4 |
| 9 | 7.5 | 4 |
| 10 | 9.0 | 4 |
| 11 | 11.0 | 5 |
| 12 | 9.0 | 6 |
| 13 | 11.0 | 6 |
| 14 | 7.5 | 7 |
| 15 | 9.0 | 7 |
| 16 | 11.0 | 7 |
| 17 | 7.5 | 8 |
| 18 | 9.0 | 8 |
| 19 | 11.0 | 8 |
| 20 | 7.0 | 9 |
+---------------+--------+---------+
第一页:SELECT_SIZE.php
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
echo "<form action=\"select_type.php\" method=\"get\">\n";
echo "<select name=\"size\">\n";
$query="SELECT sizeid,size FROM size WHERE sizeid";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$sizeid= $row['sizeid'];
$size= $row['size'];
echo "<option value=\"$sizeid\">$size</option>";
}
echo "</select>\n";
echo "<input name=\"submit\" type=\"submit\" id=\"sizeid\" value=\"submit\" />\n";
echo "</form> \n";
?>
第一个处理页面:SELECT_STYLE.php 用户选择尺码后,代码会查找所有仅适用于该尺码的鞋类类型。你会注意到 9.5 中没有——那是我的小测试。
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
$sizeid= $_GET['sizeid'];
$size= $_GET['size'];
$query="SELECT sizeid,size FROM size WHERE sizeid=$size";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error());
$sizeid= $row['sizeid'];
$size= $row['size'];
{
echo "<form action=\"select_style.php\" method=\"get\">\n";
echo "<select name=\"type\">\n";
$query="SELECT DISTINCT type.typeid, type, style_in_size.sizeid FROM style_in_size, type, style, size
WHERE style_in_size.sizeid=$sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
GROUP BY type";
$result=mysql_query($query);
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$sizeid = $row['sizeid'];
$size= $row['size'];
$typeid = $row['typeid'];
$type=$row['type'];
echo "<option value=\"$typeid\" \"$sizeid\">$type $sizeid</option>";
//I want only the "type" /$type to show in the dropdown but included SIZE for now to see if it would help pass the value to the next page
}
echo "</select>\n";
echo "<input name=\"submit\" type=\"submit\" id=\"typeid\" value=\"submit\" />\n";
echo "</form> \n";
}
?>
传递到我想显示类型和大小的这个页面(现在,因为我想为基于大小的样式创建另一个下拉列表。但是如果我无法让大小显示在这个页面上,那么我就无法继续) SELECT_STYLE.php
<?php
$con = mysql_connect("localhost", "xxxxx", "xxxxx") or die('Could not connect to server');
mysql_select_db("footwear", $con) or die('Could not connect to database');
$sizeid = $_GET['sizeid'];
$size= $_GET['size'];
$typeid = $_GET['typeid'];
$type=$_GET['type'];
$query = "SELECT type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE type.typeid=$type
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
AND style_in_size.sizeid = size.sizeid";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die(mysql_error());
$sizeid = $row['sizeid'];
$size= $row['size'];
$typeid = $row['typeid'];
$type=$row['type'];
{
echo "You've chosen $type in size $size ";
}
?>
如果我选择“Sandals”,前面的代码只会显示“You've selected Sandals in”;尺寸未显示/未通过。
我尝试了以下但没有任何效果:
$query = "SELECT type.typeid, type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE type.typeid=$type
AND sizeid = $sizeid
AND size.sizeid = style_in_size.sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid";
还:
$query = "SELECT type.typeid, type, style_in_size.sizeid FROM size, type, style, style_in_size
WHERE style_in_size.sizeid = $sizeid
AND size.sizeid = style_in_size.sizeid
AND style_in_size.styleid = style.styleid
AND style.typeid= type.typeid
AND typeid=$type";
我希望我以一种有意义的方式写了我的问题。非常感谢您的帮助和意见。提前致谢。