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> <?php install_test($installed="", $failed); ?></span></li>
Thanks in advance for any help offered.