Jump to content

Using a Variable for a Table Name


ArizonaJohn

Recommended Posts

Hello,

 

The code below works just fine.  However, I would like to use the variable "$result" where the table name "tractors" appears.  How do I do this?  (It doesn't work if I just type $result where tractors appears.)

 

I am using MySQL server version 5.0.45-log.

 

Thanks,

 

John

 

 

$result=mysql_query("SHOW TABLES FROM sand2 LIKE '%$find%'")

or die(mysql_error());

 

 

$data = mysql_query("SELECT * FROM tractors")

or die(mysql_error());

 

$info = mysql_fetch_array( $data );

 

while($info = mysql_fetch_array( $data ))

{

Print $info['site'] . " <br>";

}

Link to comment
https://forums.phpfreaks.com/topic/144884-using-a-variable-for-a-table-name/
Share on other sites

Of course not... $result is a "resource" type. If you want the actual data from that query you'll need to use any of the mysql_fetch_* functions to pull the data from that query.

 

Anyway you'll want to do a query using the INFORMATION_SCHEMA tables, not using the "SHOW TABLES" cmd.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.