search all tables

I am trying to get my code to echo the containing result if its matched from any column on a specific table. I read somewhere that there is no wildcard for columns so other than listing all the column names is there another way I can do this so that the column names are automatically generated?

there will never be multiple results so im not worried about listing them all… just want to find if the search string (which is a number) matches any field of any column on entire table.

[php]

<?php $db_server = "localhost"; $db_username = "--------------------"; $db_password = "--------------------"; $db_name = "----------------------"; mysql_connect("$db_server","$db_username","$db_password"); mysql_select_db("$db_name"); $query = mysql_query("select * from table where (ANYCOLUMN) like '$variable'"); while($r = mysql_fetch_array($query)) { echo $r; } ?>

[/php]

If there’s no column wildcard then I believe you will have to add them all to the query manually!

I think he means in the where clause. And he’s right no wildcard there.
and manually handling, ugh :slight_smile:
Answer lies in the table descriptions of MySql :slight_smile:
which gives the table schema :slight_smile: so you can build a search every column routine dynamic :slight_smile:

more info http://www.devdaily.com/blog/post/mysql/show-schema-of-table-in-mysql-database

Sponsor our Newsletter | Privacy Policy | Terms of Service