我编写了一个数据库查询来提取ColdFusion中的信息,我想知道如何将值传递给WHERE子句以获取相关数据.这是我的代码示例.任何人都可以帮忙吗?
<cfquery name="FILM_STRIP_QUERY" datasource="#dsn#">
select distinct tm.id as teachingmoduleid,
(select concat(prs.first_name, ' ',prs.last_name) AS Video_presenter from presentations pss
inner join topics tpcs on tpcs.id = pss.topic_id
inner join presenters prs on prs.id = pss.presenter_id
where pss.name = ps.name
and tpcs.title = tp.title
) AS video_presenter,
(select pss.43_png from presentations pss
inner join topics tpcs on tpcs.id = pss.topic_id
inner join presenters prs on prs.id = pss.presenter_id
where pss.name = ps.name
and tpcs.title = tp.title) AS png_name
from teaching_modules tm
inner join tm_segments sg on sg.module_id = tm.id
inner join topics tp on tp.id = sg.topic_id
inner join presenters prs on prs.id = tm.presenter_id
left outer join presentations ps on ps.id = sg.presentation_id
where tm.id =
</cfquery>
Run Code Online (Sandbox Code Playgroud)
这是调用函数
<cfloop = "FILM_STRIP_QUERY">
<!--- this is where I wanna pass the parameter--->
</cfloop>
Run Code Online (Sandbox Code Playgroud)
你的意思是这样的吗?
<cfset tmId = 5 />
<!--- or something like <cfset tmId = url.id /> --->
<cfquery name="FILM_STRIP_QUERY" datasource="#dsn#">
<!--- SELECT cols FROM wherever etc... --->
WHERE tm.id = <cfqueryparam cfsqltype="cf_sql_integer" value="#tmId#" />
</cfquery>
Run Code Online (Sandbox Code Playgroud)
您可以在没有CFQueryParam标记的情况下执行#tmid#,但最好使用它来增加安全性(验证),数据库也会缓存执行计划,希望在下次执行查询时提高性能.
| 归档时间: |
|
| 查看次数: |
3116 次 |
| 最近记录: |