[英]MySQL & Form: Populate second select options based on first selected (From same row)
My problem is that I have three different stock sizes for each product that each contain a different amount of stock (large box, medium box, small box). 我的问题是,每种产品都有三种不同的库存量,每种库存量都有不同的库存量(大包装盒,中包装盒,小包装盒)。 Each product has the same box size but the quantity per box changes.
每种产品都有相同的包装盒大小,但是每包装盒的数量会发生变化。 When the product name is selected I want to then choose the box size and the quantity value should be set corresponding to the product row in the db.
选择产品名称后,我要选择包装盒的大小,并应根据数据库中的产品行设置数量值。
------------------------------------------
|product |small |medium |large |
------------------------------------------
|Widget one |100 |275 |400 |
------------------------------------------
|Widget two |45 |100 |150 |
------------------------------------------
|Widget three |125 |150 |250 |
I already use php to get the select option product names from the db 我已经使用php从数据库获取选择选项产品名称
$product_select = mysql_query("SELECT * FROM products");
echo '<select name="Product" id="product">';
while ($row_item = mysql_fetch_array($product_select)){
$pname = $row_item["product"];
echo '<option value="' . htmlspecialchars($pname) . '">' . htmlspecialchars($pname) . '</option>';
Then I need something like this that gets the row values for small medium and large based on the selected product from above: 然后,我需要类似这样的东西,它根据上面选择的产品获取中小型和大型的行值:
<select><option value=" ">Small</option><option value=" ">Medium</option><option value=" ">Large</option></select>
EDIT 编辑
I have been trying to figure this out all night. 我一直想通宵达旦。 Is this even possible?
这有可能吗? should I just try and go a different route?
我应该试着走另一条路吗?
You have 3 ways to implement this: 您有3种方法可以实现此目的:
Store serialized values of stock inside first select and populate second select from that values. 将股票的序列化值存储在第一选择中,然后从该值中填充第二选择。 For example:
例如:
<select> <option values="100|275|400">Widget one</option> ... </select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.