• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

PHP - MySQL -'SHOW tables'

In the following dropdown I use 'Show tables' to populate my dropdown box with all tables on database X.

Is there an alternative to 'Show tables' where I can restrict the tables shown to for example all those starting with S.?

This is the code snippet

 //Tables drop-down
 $result = mysql_query("SHOW tables") or die("Cannot list table names.");
echo "
<form name=\"table_browser\" action=\"".$PHP_SELF."\" method=\"GET\" >
    <select name=\"t\" onChange=\"javascript:submit();\">
        <option>Select a table</option>
";
while ($row = mysql_fetch_row($result)){
    echo "        <option value=".$row[0].">".$row[0]."</option>\n";
}
echo "    </select>
</form>\n";

if (!isset($t)){
    die("Please select a table");
}
0
thehaze
Asked:
thehaze
1 Solution
 
nicholassolutionsCommented:
SHOW TABLES FROM db_name LIKE 's%'

Cheers,
Matt
0
 
KaritzCommented:
also check if you have a database selected.

if not select the database.

put  a check also, to see if the database has tables or not
0
 
gruntarCommented:
Hi

You should create query like this.
$result = mysql_query("SHOW TABLES") or die('Error: ' . mysql_error());

That way MySQL will describe you What the problem is.

Cheers
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now