我有一个使用名字,姓氏和DOB值的表格。我有两个表:TableA和TableB。每个表都可以包含在表格中输入的人名信息。在ColdFusion中,我想做的是编写一个查询,查询用户输入并比较包含信息的表。一旦找到包含用户信息的表,就显示该表中的特定列。
下面是表格:
<Form name="ERHospital" Method="Post" class="a">
<div align="center" style="margin-top:10pt; margin-bottom:10pt">
<table Border="0" width="100%" align="center" cellpadding=0 cellspacing=0 >
<tr>
<td class="m" id="fName">First Name </td>
<td>
<input class="a" id="FirstName" name="FirstName" value="<cfoutput></cfoutput>" size="15">
</td>
<td class="m" id="lName">Last Name </td>
<td>
<input class="a" id="LastName" name="LastName" value="<cfoutput></cfoutput>" size="15">
</td>
<td class="m" id="DOB">
DOB<br />
<font color="##CC0000" size="1" style="italic">(mm/dd/yyyy)</font>
</td>
<td>
<input type="text" id="BirthDt" name ="BirthDt" id="BirthDt" maxlength="10" size="10">
</td>
</tr>
<tr>
<!---<td class="m" id="Hospital">Hospital</td>
<td>
<select name="hosp" id="hosp"></select>
</td>--->
<!---<td class="m" colspan="2"></td>
<td class="m">
<input type="button" value="Submit" onClick="SubmitMe(); checkFields();" name="SubmitEmpBtn" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold">
</td>
<td align="left">
<input type="button" name="Clear" value="Clear" onClick="ClearForm()" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold">
</td>
</tr>--->
</table>
<div style="text-align:center; margin-top:15pt"><input type="button" value="Submit" onClick="SubmitMe(); checkFields();" name="SubmitEmpBtn" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold"> <input type="button" name="Clear" value="Clear" onClick="ClearForm()" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; font-weight:bold"> </div>
<!---<table align="center">
<TR>
<TD align="center"><input type="button" value=" Submit " onClick="SubmitMe()" name="SubmitEmpBtn" style="font-size:14px; font-family:Arial, Helvetica, sans-serif"> <input type="button" name="Clear" value=" Clear " onClick="ClearForm()" style="font-size:14px; font-family:Arial, Helvetica, sans-serif"> </td>
</tr>
</table>
</table>--->
</div>
</FORM>
答案 0 :(得分:4)
如果保证用户只能在一个表中,则可以使用UNION ALL
,如下所示:
<cfquery name="myquery" datasourse="#myDSN#">
SELECT <userField1>, <userField2>
FROM Table1
WHERE
FirstName = <cfqueryparam value="#form.firstname#" cfsqltype="cf_sql_varchar">
AND
LastName = <cfqueryparam value="#form.lastname#" cfsqltype="cf_sql_varchar">
UNION ALL
SELECT <userField1>,<userField2>
FROM Table2
WHERE
FirstName = <cfqueryparam value="#form.firstname#" cfsqltype="cf_sql_varchar">
AND
LastName = <cfqueryparam value="#form.lastname#" cfsqltype="cf_sql_varchar">
</cfquery>
如果该用户仅在一个表中,则只会得到所请求用户的结果。
编辑:我还要补充一点,我不喜欢在不确保已对它们进行清理的情况下在SQL查询中使用表单,URL或任何其他外部变量。但这是 WHOLE 不同类型的讨论。 :-)