Indicate database elements in a form if they exist

I’m trying to pull the names of tables from a database and if the table exist I want the checkbox in a form to be checked. If it doesn’t exist I’d like to display a message. First to pull the names of the tables from the database I have this code. But it is not printing all of the tables when using print_r().

mysql_select_db($dbname);       
        $showtablequery = "SHOW TABLES	FROM $dbname";
        global $installed, $failed;
        $showtablequery_result	= mysql_query($showtablequery);
        $showtablerow = mysql_fetch_array($showtablequery_result);
        print_r($showtablerow);

I’m stuck here until I can get all of the table names in an array.
To do the same thing with the database I have had success with the following, but there is no query that I know of that will allow me to get the table names as I do here with the database name.

include_once 'db_conn.php';
mysql_select_db($dbname);

$installed = 'checked';
$failed = 'Failed! The Database was not created. Check your connection to the MySQL server.'; 
function install_test($installed, $failed) {
global $dbname, $installed, $failed;
/*
* All installed elements should be in an array and accessed foreach and error or success logged accordingly
*
*/
$db_test = mysql_select_db($dbname);
	if($db_test) {
	echo $installed;
}
else {
    echo $failed;
	}

And then to accomplish what I want with the form I insert this code into the input field of the form.

<li><input type="checkbox" name="dbase" value="yes" <?php install_test($installed, $failed=""); ?> /><label for="dbase" class="label">Database</label><span>&nbsp;&nbsp;<?php install_test($installed="", $failed); ?></span></li>

Thanks in advance for any help offered.

Thanks Immerse. Your code was printing out “1111”. I altered it as follows and was able to get the table names. Thanks for the loop to start with. What was I thinking not using it!

 mysql_select_db($dbname);
        $showtablequery = "SHOW TABLES FROM $dbname";
        global $installed, $tbfailed;
        $showtablequery_result = mysql_query($showtablequery);
        while($showtablerow = mysql_fetch_array($showtablequery_result)) {
            $tables = $showtablerow[0];
             echo $tables;
        }

The reason why it’s not showing all the tables is because you’re only print_r()'ing one row.

Try this:


        mysql_select_db($dbname);       
        $showtablequery = "SHOW TABLES	FROM $dbname";
        global $installed, $failed;
        $showtablequery_result	= mysql_query($showtablequery);
        while($showtablerow = mysql_fetch_array($showtablequery_result) !== false) {
             print_r($showtablerow);
        }

I’ve added a while loop which will print_r() the rows, one by one. (code is untested, btw)