Reply to Re: Passing mysql table names to php functions?

Your name:

Reply:


Posted by Jose da Silva on 02/27/07 14:36

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...@gmail.com 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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация