简体   繁体   English

使用具有来自另一个表的字段的表单更新表

[英]Update table using form with field from another table

I have two tables one tblEmployee and another tblCity . 我有两个表,一个是tblEmployee ,另一个是tblCity

The two tables are setup like this: 这两个表的设置如下:

tblEmployee   
-------------
employeeID       
cityID                
name
sex
contactNo

tblCity
-------------
cityID
cityName

I would like to create a form whereby an admin can update an employee's details. 我想创建一个表单,以便管理员可以更新员工的详细信息。 The form has a drop down box which is populated by the cityName s in tblCity . 表单具有一个下拉框,该框由cityName中的tblCity

I am struggling coming up with a query to allow the admin to select one of these cities from the drop down which will update the employee's cityID to the corresponding city in tblCity . 我竭力想出一个查询来允许管理员选择这些城市,从下拉将更新员工的一个cityID在相应的城市tblCity

Many thanks in advance! 提前谢谢了!

I suspect what you want is to setup the select values like this: 我怀疑您想要的是设置选择值,如下所示:

<option value="cityID">cityName</option> 

The cityID will be submitted, and then you put that value in the tblEmployee.cityID . 将提交cityID ,然后将该值放入tblEmployee.cityID

For example: 例如:

<p>
    <select id="sel1">
        <option value="001">Auburn</option>
        <option value="002">Austin</option>
        <option value="003" selected>Dallas</option>
        <option value="004">Houston</option>
    </select>
    <button rel="sel1">Show selected value (with value attribute)</button>
</p>
<p>
    <select id="sel2">
        <option>Auburn</option>
        <option>Austin</option>
        <option selected>Dallas</option>
        <option>Houston</option>
    </select>
    <button rel="sel2">Show selected value (no value attribute)</button>
</p>

$('button').click(function(){
    var $sel = $('#' + $(this).attr('rel')).find('option:selected');
    console.log($sel.val() + ' - ' + $sel.text());
});

http://jsfiddle.net/5McA9/1/ http://jsfiddle.net/5McA9/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM