Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay list of tables as drop down box
    primarykey
    data
    text
    <p>I'm trying to code a drop down box that displays all table names from a database but I can't seem to figure out why it's not working. I'm getting the drop down box on the screen but it seems to be empty and my submit button isn't appearing either.</p> <p>I just can't see where I've gone wrong, here's all my relevant code:</p> <p>index.php</p> <pre><code>include_once 'db.php'; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST"&gt; &lt;select name="Tables" id="ddTables"&gt; &lt;?php $tableResults = getTableList(); if($tableResults) { if($tableResults-&gt;rowCount() &gt; 0) { $tables = $tableResults-&gt;fetchAll(PDO::FETCH_NUM); foreach($tables as $table) { $name = $table[0]; echo '&lt;option value="'.$name.'"&gt;'.$name.'&lt;/option&gt;'; } } } else { echo '&lt;option value="0"&gt;No Data&lt;/option&gt;'; } ?&gt; &lt;/select&gt; &lt;input type="submit" id="tableSubmit" value="Submit"/&gt; &lt;/form&gt; </code></pre> <p>db.php</p> <p>getConnection function:</p> <pre><code>//main database connection varaibles $DCONFIG_server = "localhost:8888"; $DCONFIG_DBUser = "root"; $DCONFIG_DBPass = "password"; $DCONFIG_DBName = "ISAD235"; try { $conn = new PDO("mysql:host=$DCONFIG_server;dbname=$DCONFIG_DBName", $DCONFIG_DBUser, $DCONFIG_DBPass); } catch (PDOException $ex) { echo $ex-&gt;getMessage(); } return $conn; function getConnection() { //main database connection varaibles $DCONFIG_server = "localhost:8888"; $DCONFIG_DBUser = "root"; $DCONFIG_DBPass = "password"; $DCONFIG_DBName = "ISAD235"; try { $conn = new PDO("mysql:host=$DCONFIG_server;dbname=$DCONFIG_DBName", $DCONFIG_DBUser, $DCONFIG_DBPass); } catch (PDOException $ex) { echo $ex-&gt;getMessage(); } return $conn; } function runSQL($sql) { $mysqlConnection = getConnection(); $ResultSet = $mysqlConnection-&gt;query($sql); return $ResultSet; } function getTableList() { $sql = "SHOW TABLES"; $ResultSet = runSQL($sql); if(!$ResultSet) { echo "Table list not found"; } return $ResultSet; } </code></pre> <p>Any help would be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload