php - Looping through table columns -
i have query supposed loop through tables in database. fine, test outputting table names.
but, i'm trying loop through every column in database use inside query.
this current code, loops through tables in database:
<?php $host = "127.0.0.1"; $username = "username"; $password = "password"; $database = "database"; $link = new mysqli($host, $username, $password, $database); if($link->connect_error) { die("connection died: ".$link->connect_error); } $showtables = $link->query("show tables;"); foreach($showtables->fetch_all() $table) { printf($table[0] . "\n"); // i'm trying achieve: foreach(/* ??? */ $column) { printf("\t- ".$column."\n"); } } ?>
could lend hand? thank you!
something :
$host = "127.0.0.1"; $username = "username"; $password = "password"; $database = "database"; $link = new mysqli($host, $username, $password, $database); if($link->connect_error) { die("connection died: ".$link->connect_error); } $showtables = $link->query("describe name_of_table;"); foreach($showtables->fetch_all() $table) { printf($table[0] . "\n"); }
if want table in database use sql :
select * information_schema.columns table_schema = 'your_db' order table_name,ordinal_position
Comments
Post a Comment