Re: Trouble passing mysql table name to php function and using it!
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Tue, 27 Feb 2007 11:27:33 -0500
kennthompson@xxxxxxxxx wrote:
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.
This should work fine. What do you get back as an error message? How are you calling the function?
What happens if you do the following:
function fms_get_info($tableName)
{
$sql = "select * from $tableName";
echo $sql . "<br>\n";
$result = mysql_query($sql) ;
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
/* do something */
}
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Trouble passing mysql table name to php function and using it!
- From: kennthompson
- Re: Trouble passing mysql table name to php function and using it!
- References:
- Trouble passing mysql table name to php function and using it!
- From: kennthompson
- Trouble passing mysql table name to php function and using it!
- Prev by Date: Re: is PHP less secure than Perl, Python, or Ruby?
- Next by Date: Re: is PHP less secure than Perl, Python, or Ruby?
- Previous by thread: Trouble passing mysql table name to php function and using it!
- Next by thread: Re: Trouble passing mysql table name to php function and using it!
- Index(es):
Relevant Pages
|