【发布时间】:2012-09-21 14:08:48
【问题描述】:
我正在运行Coldfusion8/MySQL 5.0.88。
我的数据库中有两个表:
modules
textblocks
我的网站运行多种语言,所以我在每个页面的开头都这样做,以根据用户选择的语言从数据库中加载文本块。
<cfquery datasource="#Session.datasource#" name="texte">
SELECT *
FROM textblocks
WHERE lang = <cfqueryparam value = "#Session.lang#" cfsqltype="cf_sql_varchar" maxlength="2">
</cfquery>
<cfoutput query="texte">
<cfset "#trim(label)#" = "#trim(content)#">
</cfoutput>
如果我需要一个文本块,我可以像这样简单地使用label:
<cfoutput>#tx_hello_world#</cfoutput>
我的问题在于包含模块列表的第二张表。
每个模块都有自己的描述(标题、子标题、信息、项目符号 1-5)。我必须遍历所有模块(25),所以我只是将labels 存储在数据库中,希望进行一次循环并从数据库中输出labels。不幸的是,输出 label123 返回
#label123#
vs我希望
"text from table textblocks stored at label123"
问题:
是否可以在 MySQL 中存储“动态变量”并在输出这些变量时检索它们的基础值?如果不是,那么在一个循环中输出 25 个模块而不说“如果这是模块 A,则取文本 tx_module_a_title,否则如果...”的更好方法是什么?
谢谢!
编辑:
所以我希望避免在每个循环上都运行这个:
<cfif mods.module_name EQ "agents">
<cfset variables.module_header = tx_module_b2b_agents_title>
<cfset variables.module_subheader = tx_module_b2b_agents>
<cfset variables.module_info = tx_module_b2b_agents_info>
<cfset variables.module_bull_1 = tx_module_b2b_agn_accounts>
<cfset variables.module_bull_2 = tx_module_b2b_agn_price_clients>
<cfset variables.module_bull_3 = tx_module_b2b_agn_client_mgt>
<cfset variables.module_bull_4 = tx_module_b2b_agn_create_retailer>
<cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
<cfset variables.module_usage_tx = tx_vertreter/tx_gen_month>
<cfelseif mods.module_name EQ "preorder">
<cfset variables.module_header = tx_module_b2b_preorder_title>
<cfset variables.module_subheader = tx_module_b2b_preorder>
<cfset variables.module_info = tx_module_b2b_preord_info>
<cfset variables.module_bull_1 = tx_module_b2b_pre_split_type>
<cfset variables.module_bull_2 = tx_module_b2b_pre_qty_y_n>
<cfset variables.module_bull_3 = tx_module_b2b_pre_deliverydate>
<cfset variables.module_bull_4 = tx_module_b2b_exp_grace>
<cfset variables.module_bull_5 = "">
<cfset variables.module_usage_tx = tx_gen_month >
<cfelseif mods.module_name EQ "export">
<cfset variables.module_header = tx_module_b2b_export_title>
<cfset variables.module_subheader = tx_module_b2b_export>
<cfset variables.module_info = tx_module_b2b_export_info>
<cfset variables.module_bull_1 = tx_module_b2b_exp_pricelists>
<cfset variables.module_bull_2 = tx_module_b2b_exp_currencies>
<cfset variables.module_bull_3 = tx_module_b2b_exp_customerlist>
<cfset variables.module_bull_4 = tx_module_b2b_exp_regional_assortme>
<cfset variables.module_bull_5 = tx_module_b2b_exp_grace>
<cfset variables.module_usage_tx = tx_gen_month>
... 22 else-ifs to go
</cfif>
如果我可以将文本块存储在数据库模块记录中tx_ 值后面,我可以从那里检索它们。
【问题讨论】:
标签: mysql variables dynamic coldfusion