“双” PHP 中的评估
大家早上好!
我的 MySQL 查询返回一个 PHP 变量名称,我想在输出它时对其进行“双重”评估。对我来说,最好以身作则。
在静态资源页面上,我有:
$page1 = "test1.php";
$page2 = "test2.php";
我的名为 tbl_pages 的 MySQL 表在 fld_pagename 下包含 2 个条目:$page1 和 $page2。这样,我认为我只定义 $page1 和 $page2 一次。
现在,在我正在处理的页面上,我有一个返回页面名称的查询:
$query = mysql_query("SELECT fld_pagename FROM tbl_pages WHERE fld_show = 1 ORDER BY fld_ref");
while($row = mysql_fetch_array($query)){
$nameofpage = $row['fld_pagename'];
echo "$nameofpage",'<br />';
}
但是,变量周围的双引号仅将变量评估为一级。它的输出是:
$page1<br />$page2<br />
但我希望在输出之前对这些变量进行评估:
test1.php<br />test2.php<br />
非常感谢任何想法!
Morning all!
My MySQL query returns a PHP variable name which I'd like to "double" evaluate when I output it. It may be best for me to do this by example.
On the static resources page I have:
$page1 = "test1.php";
$page2 = "test2.php";
And my MySQL table called tbl_pages contains 2 entries under fld_pagename: $page1 and $page2. That way, I figure that I only define $page1 and $page2 once.
Now, on the page I'm working on, I have a query which returns the name of the page:
$query = mysql_query("SELECT fld_pagename FROM tbl_pages WHERE fld_show = 1 ORDER BY fld_ref");
while($row = mysql_fetch_array($query)){
$nameofpage = $row['fld_pagename'];
echo "$nameofpage",'<br />';
}
However, the double quotes around the variable only evaluate the variable to one level. Its output is:
$page1<br />$page2<br />
But I want these variables to be evaluated before output:
test1.php<br />test2.php<br />
Any thoughts much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果我理解正确,您可以使用此 PHP 功能(示例):
或者,使其与您的系统兼容...
If I get you correctly, you can use this PHP feature (example):
Or, to make it compatible with your system...
如果您在评估所引用的页面之后,那么这会起作用:
If you're after evaluating the pages you've referenced, then this would work:
如果您只存储变量名称而不存储 $,则可以使用 PHP 的变量功能的变量
可以从存储的输入中删除 $
If you only store variable name without $ you can use variable of variable feature of PHP
can remove $ from input stored
看来你的数据库设计是错误的。
将 PHP 变量名称存储在数据库中的原因并不单一。
存储页面名称本身就可以了
it seems your database design is wrong.
There is not a single reason to store PHP variable names in the database.
Store pagenames itself and you'll be okay