gpt4 book ai didi

mysql - 如何在 MySQL 中存储 Coldfusion #variable# 并从数据库输出变量值(而不是变量名称)?

转载 作者:行者123 更新时间:2023-11-29 08:45:17 24 4
gpt4 key购买 nike

我正在运行 Coldfusion8/MySQL 5.0.88

我的数据库中有两个表:

modules
textblocks

我的网站运行多种语言,因此我在每个页面的开头执行此操作,以根据用户选择的语言从数据库加载文本 block 。

<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>

如果我需要一个文本 block ,我可以简单地使用标签,如下所示:

<cfoutput>#tx_hello_world#</cfoutput>

我的问题是第二个表,其中包含模块列表。

每个模块都有自己的描述(标题、副标题、信息、项目符号 1-5)。我必须循环遍历所有模块 (25),因此我只是将标签存储在数据库中,希望执行单个循环并从数据库输出标签。不幸的是输出label123返回

 #label123#

与我的希望

 "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>

如果我可以将文本 block 存储在数据库模块记录中的 tx_ 值后面,我就可以从那里检索它们。

最佳答案

当您从数据库输出内容时,您可以在内容上使用 de()evalaute() 来处理变量。您可能需要使用嵌套组合。我忘记了确切的语法。De(evaluate('#var#')) 或类似的东西。

但是,如果内容中有任何其他非 var 的 # ,这将会出现问题。我建议改用词典。请参阅这篇文章Content Management : Processing Dynamic Content

关于mysql - 如何在 MySQL 中存储 Coldfusion #variable# 并从数据库输出变量值(而不是变量名称)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12661200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com