I am looking on how to retrieve a table name that is currently active so that I can store that table name into a variable and then use it in a query that will need to fetch the tablename the data is located in. I have looked on Stack and Google and cannot find a simple solution to this. I wish I could provide an example of what I am already working with but the truth is that I have not found anything of use that will help me do this simple task.
I want to select table name and store, that is all. Sounds simple enough, I hope I don't get down votes for this one but I really need to find an answer to this even if points are lost.
To clarify: I want to find a way to use the same script for different table names. We have different categories of tables. I would like the query to search certain columns on a specific tables based on the current table that is being accessed. We have table 1 and table 2 with the some columns that are the same name but only table 1 is being accessed at the moment. If administrators want to make a change to image in a table it needs to be done in the table that is currently accessed so that I do not duplicate my code just to accommodate different table names.
Sounds not simple.
Probably you have some "problems" with understanding how to work with database.
You (your app-code) should always know names of all database tables it wants to use.
Just know. Not fetching them.
Fetching them have no sense.
To write queries in your app-code you should know not only then tables names but all their fields, their types, in other words structure.
If you want tables from a specific database, let's say the database "books", then it would be
show tables from books;
You only need the LIKE part if you want to find tables whose names match a certain pattern. e.g.,
show tables from books like '%book%';
would show you the names of tables that have "book" somewhere in the name.
Furthermore, just running the "show tables" query will not produce any output that you can see. SQL answers the query and then passes it to PHP, but you need to tell PHP to echo it to the page.
Since it sounds like you're very new to SQL, I'd recommend running the mysql client from the command line (or using phpmyadmin, if it's installed on your system). That way you can see the results of various queries without having to go through PHP's functions for sending queries and receiving results.
If you have to use PHP, here's a very simple demonstration. Try this code after connecting to your database:
$result = mysql_query("show tables"); // run the query and assign the result to $result
while($table = mysql_fetch_array($result)) { // go through each row that was returned in $result
echo($table[0] . "<BR>"); // print the table that was returned on that row.
}