php - creating a dropdown of available tables in a DB -


this bit of code below connects db(using config.php) , creates below dropdown.

include "config.php"; // database connection using pdo  //$sql="select name,id student";   $sql="select name,id student order name";   /* can add order clause sql statement if names displayed in alphabetical order */  echo "<select name=student value=''>student name</option>"; // list box select command  foreach ($dbo->query($sql) $row){//array or records stored in $row  echo "<option value=$row[id]>$row[name]</option>";   /* option values added looping through array */   }   echo "</select>";// closing of list box 

this dropdown code created, , can run see in action.

<br>  <br> list box here  <select name=student value=''>student name</option>    <option value=1>john deo</option>    <option value=2>max ruin</option>    <option value=3>arnold</option>    <option value=4>krish star</option>    <option value=5>john mike</option>    <option value=6>alex john</option>    <option value=7>my john rob</option>    <option value=8>asruid</option>    <option value=9>tes qry</option>    <option value=10>big john</option>    <option value=11>ronald</option>    <option value=12>recky</option>    <option value=13>kty</option>    <option value=14>bigy</option>    <option value=15>tade row</option>    <option value=16>gimmy</option>    <option value=17>tumyu</option>    <option value=18>honny</option>    <option value=19>tinny</option>    <option value=20>jackly</option>    <option value=21>babby john</option>    <option value=22>reggid</option>    <option value=23>herod</option>    <option value=24>tiddy now</option>    <option value=25>giff tow</option>    <option value=26>crelea</option>    <option value=27>big nose</option>    <option value=28>rojj base</option>    <option value=29>tess played</option>    <option value=30>reppy red</option>    <option value=31>marry toeey</option>    <option value=32>binn rott</option>    <option value=33>kenn rein</option>    <option value=34>gain toe</option>    <option value=35>rows noump</option>  </select>  <br>  <br>

what want change line $sql="select name,id student order name"; dropdown contain tables in db example show tables. given have provided can done? or should use different method? if show tables e.g. tables begin tab.

like

<br>  <br> list box here available tables  <select name=student value=''>tablename</option>    <option value=1>table1</option>    <option value=2>table2</option>    <option value=3>table3</option>  </select>  <br>  <br>

edit1 these lines think need change; problem $sql="show tables";

echo "<option value=$row[id]>$row[name]</option>";

i tested , worked using server. table_schema='yourdbname' key because otherwise can dozens of random tables.

select table_name information_schema.tables table_schema='yourdbname' 

you should able replace query , same sort of drop down. sure want people know names of tables though, security reasons?


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo