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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.