PHP - MySQL -'SHOW tables'

Posted on 2004-11-23
Last Modified: 2013-12-12
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>

if (!isset($t)){
    die("Please select a table");
Question by:thehaze
    LVL 15

    Accepted Solution

    SHOW TABLES FROM db_name LIKE 's%'

    LVL 5

    Expert Comment

    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
    LVL 9

    Expert Comment


    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.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now