note 94064 deleted from book.mssql by danbrown
| From: | danbrown@php.net | Date: | Wed, 14 Oct 2009 21:06:15 +0000 |
| Subject: | note 94064 deleted from book.mssql by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161738@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
CORRECTION FOR
exidas at madnes dot eu
(The original script wasn't maintaining the columns returned with their related table.)
<?php
$all = MSSQL_Query("select TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS order by
TABLE_NAME, ORDINAL_POSITION");
// Check if there were any records found
if(!mssql_num_rows($all))
{
echo 'No records found';
} else {
$tables = array();
$columns = array();
while($fet_tbl = MSSQL_Fetch_Assoc($all)) { // PUSH ALL TABLES AND COLUMNS INTO THE ARRAY
$tables[] = $fet_tbl[TABLE_NAME];
$columns[$fet_tbl[TABLE_NAME]][] = $fet_tbl[COLUMN_NAME];
}
$sltml = array_count_values($tables); // HOW MANY COLUMNS ARE IN THE TABLE
foreach($sltml as $table_name => $id) {
echo "<h2>". $table_name ." (". $id
.")</h2><ol>";
for($i = 0; $i <= $id-1; $i++) {
echo "<li>". $columns[$table_name][$i] ."</li>";
}
echo"</ol>";
}
}
// Free the query result
mssql_free_result($all);
?>