Re: Passing mysql table names to php functions?



Hello, have you tried some debug?

Try to
echo "My table name in function: ".$tableName;

Maybe the variable is not getting the value you expected

Regards
jose Silva

On Feb 27, 2:25 pm, kennthomp...@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.


.



Relevant Pages

  • RE: [PHP] PHP - Web/list Question...
    ... this is simply a demo of breaking a list up across multiple pages... ... No offense taken. ... However, now seeing what you actually asked, I would use a database to record each item the user picked and then when displaying the pages again, would check the dB first to see if the item should be noted as checked or not. ... This of course would require the user to post/get each page UNLESS you use ajax and write to the dB via a slave php script. ...
    (php.general)
  • RE: [PHP] How to Execute Multiple SQL Updates Using PHP
    ... [PHP] How to Execute Multiple SQL Updates Using PHP ... values) are being placed in the SQL query. ...
    (php.general)
  • Re: "call to undefined function" mysql_error when adding new rows to table
    ... I have recently set up a mysql database of local pubs, ... when I try to add a new pub I get an error message "call to undefined ... Shouldn't be any PHP problem. ...
    (comp.lang.php)
  • Re: A good editor
    ... Create a macro so you ... * Multiple languages - I use UE for php, html, css, javascript, perl and c. ... I work at an advertising agency where there are all Macs. ...
    (comp.lang.php)
  • Re: breaking into J2EE: steep curve or wrong approach?
    ... > a MySQL database. ... > I'd like to recode the PHP functionality as either servlets or JSPs. ... You need to understand servlets. ...
    (comp.lang.java.programmer)