|
Posted by Tom on 02/27/07 19:04
On 27 Feb 2007 07:02:52 -0800, kennthompson@gmail.com wrote...
>
>
>The name passes -- the echo test works; it just won't work as a mysql
>table. The variable is getting there, but mysql for some reason does
>not recognize it. I've read something about prepare and execute in
>mysql, but not sure this is the answer to my problem.
If your echo is returning the right values, may be worth trying the
mysql_error() function to check if there is a problem with the SQL command being
submitted.
Tom
--
Newsguy.com
75+ days of Binary and Text Retention!
Higher levels of article completion!
Broader coverage of newsgroups
>
>On Feb 27, 8:36 am, "Jose da Silva" <josedasi...@gmail.com> wrote:
>> 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.- Hide quoted text -
>>
>> - Show quoted text -
>
[Back to original message]
|