在PHP中使用多个表填充dropDownBoxes [英] Populating dropDownBoxes using multiple tables in PHP

查看:78
本文介绍了在PHP中使用多个表填充dropDownBoxes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我首先要声明我不是网络开发人员,但是已经能够为我的公司完成一个简单的库存系统.其次,我整个下午都在用Google搜索这个问题,没有运气可以找到可以应用到我的特定应用程序中的东西.
我想根据在componentType下拉框(dropdown1)中选择的componentType仅填充正确组件类型的序列号的序列号下拉框(dropdown2).下面是表格的必要部分和我当前拥有的代码. Dropdown1正在显示正确的值,但我需要dropdown2才能随着dropdown1的更改而动态更改.预先感谢您提供的任何帮助或指导.

表格组件
idComponent INT(主键)
serialComponent VARCHAR
idComponentType INT(ComponentType的外键)

表格ComponentType
idComponentType INT
nameComponentType VARCHAR

I first would like to state I am not a web developer but have been put in a position to complete a simple inventory system for my company. Secondly I have googled this question all afternoon and have had no luck finding anything that I can wade through and apply to my specific application.
I want to populate a serial number dropdown box (dropdown2) with only the serial numbers of the correct component types based on the componentType chosen in the componentType dropdown box(dropdown1). Below is the needed portions of the tables and the code I have currently. Dropdown1 is displaying the proper values but I need dropdown2 to change dynamically as dropdown1 is altered. Thank you in advance for any help or guidance available.

TABLE Components
idComponent INT(Primary KEY)
serialComponent VARCHAR
idComponentType INT (Foreign Key to ComponentType)

TABLE ComponentType
idComponentType INT
nameComponentType VARCHAR

$queryComponentType = "SELECT idComponentType,nameComponentType FROM ComponentType";

//Execute query, or return an error message if there is a problem.
$result1 = mysql_query($queryComponentType) or die(mysql_error());

$dropdown1 = "<select nameComponentType = 'ComponentType'>";

while($row=mysql_fetch_assoc($result1)){
	$dropdown1 .="\r\n<option value='{$row['nameComponentType']}'>
                     {$row['nameComponentType']}</option>";
}

$dropdown1 .= "\r\n</select>";

echo"<p>Component Types: ".$dropdown1 ."</p>"; 
	
$querySerialComponent = "SELECT serialComponent,idComponentType FROM Components";

//Execute query, or return an error message if there is a problem.
$result2 = mysql_query($querySerialComponent) or die(mysql_error());

$dropdown2 = "<select serialComponent = 'Components'>";

while($row=mysql_fetch_assoc($result2)){
       $dropdown2 .="\r\n <option value='{$row['serialComponent']}'> 
                    $row['serialComponent']}<;/option>";
}

$dropdown2 .= "\r\n</select>";

echo"<p>Component Serial Numbers: ".$dropdown2 ."</p>"; 

推荐答案

queryComponentType = " ; // 执行查询,或者在出现问题时返回错误消息.
queryComponentType = "SELECT idComponentType,nameComponentType FROM ComponentType"; //Execute query, or return an error message if there is a problem.


result1 = mysql_query(
result1 = mysql_query(


queryComponentType)
queryComponentType) or die(mysql_error());


这篇关于在PHP中使用多个表填充dropDownBoxes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆