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("se lect * 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($t ableName)
{
$result = mysql_query("se lect * from $tableName") ;
for ($i = 0; $i < mysql_num_rows( $result); $i++)
{
/* do something */
}
}
/* Main */
fms_get_info($t ableInfo);
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.
name already defined everything works fine as the following script
illustrates.
<?php
function fms_get_info()
{
$result = mysql_query("se lect * 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($t ableName)
{
$result = mysql_query("se lect * from $tableName") ;
for ($i = 0; $i < mysql_num_rows( $result); $i++)
{
/* do something */
}
}
/* Main */
fms_get_info($t ableInfo);
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.
Comment