麻烦将mysql表名传递给php函数并使用它! [英] Trouble passing mysql table name to php function and using it!
问题描述
麻烦在php中传递mysql表名。如果我使用现有的表
名称已经定义,一切正常,如下面的脚本
说明的那样。
<?php
函数fms_get_info()
{
$ result = mysql_query(" select * from $ tableInfo");
for($ i = 0; $ i< mysql_num_rows($ result); $ i ++)
{
/ *做点什么* /
}
}
/ * Main * /
fms_get_info();
但是如果我将变量表名传递给函数它就不会工作。
<?php
函数fms_get_info($ tableName)
{
$ result = mysql_query(" select * from $ tableName");
for($ i = 0; $ i< mysql_num_rows ($ result); $ i ++)
{
/ *做点什么* /
}
}
/ * Main * /
fms_get_info($ tableInfo);
我需要使用相同的功能来收集多个信息
表格随意而不为每个创建不同的函数
可能
mysql数据库表的名称。我觉得这很容易,但我好几次尝试都失败了。
result = mysql_query(" select * from
tableInfo");
for(
i = 0;
Trouble passing mysql table name in php. If I use an existing table
name already defined everything works fine as the following script
illustrates.
<?php
function fms_get_info()
{
$result = mysql_query("select * from $tableInfo") ;
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
/* do something */
}
}
/* Main */
fms_get_info();
But it won''t work if I pass a variable table name to the function.
<?php
function fms_get_info($tableName)
{
$result = mysql_query("select * from $tableName") ;
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
/* do something */
}
}
/* Main */
fms_get_info($tableInfo);
I need to use the same function to gather information from multiple
tables at will without creating a different function for each
possible
mysql database table by name. I thought this would be easy, but I
have failed at several tries.
result = mysql_query("select * from
tableInfo") ;
for (
i = 0;
这篇关于麻烦将mysql表名传递给php函数并使用它!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!