This is a discussion on My crappy code within the PHP Language forums, part of the PHP Programming Forums category; Doesn't work. Desired output: tables and their columns from a MySQL database. Assume the link is already established. The ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Doesn't work.
Desired output: tables and their columns from a MySQL database. Assume the link is already established. The tables are being output already, and an empty string where the column names should be. Code: global $DB; open_cell(); $tables = mysql_list_tables($DB); for ($i = 0; $i < mysql_num_rows($tables); $i++) { $tablename = mysql_tablename($tables, $i); echo "Table: ", $tablename, "<br><br>\n"; $fieldlist = mysql_field_name($DB, $tablename); for ($a = 0; $a < mysql_num_fields($fieldlist); $a++) { $fieldname = mysql_fetch_field($fieldlist, $a); $field_output = mysql_fetch_row($fieldname, $a); echo $fieldname . " <-> "; // <- this is going to look unfinished } echo "<br><br>\n"; } I have a foreboding feeling that my approach is what is B0rK3n. I also tried mysql_fetch_array and imploding it for a delimited list. No dice. My query is broken in there somewhere and I'm just not getting it. -- Bachelors' wives and old maids' children are always perfect. -- Nicolas Chamfort |
|
|||
|
Handover Phist blithely blithered
> Doesn't work. > > Desired output: > > tables and their columns from a MySQL database. Assume the link is > already established. The tables are being output already, and an empty > string where the column names should be. > > Code: > > global $DB; > open_cell(); > > $tables = mysql_list_tables($DB); > for ($i = 0; $i < mysql_num_rows($tables); $i++) { > $tablename = mysql_tablename($tables, $i); > echo "Table: ", $tablename, "<br><br>\n"; > > $fieldlist = mysql_field_name($DB, $tablename); > for ($a = 0; $a < mysql_num_fields($fieldlist); $a++) { > $fieldname = mysql_fetch_field($fieldlist, $a); > $field_output = mysql_fetch_row($fieldname, $a); > echo $fieldname . " <-> "; // <- this is going to look unfinished > } > echo "<br><br>\n"; > } > > I have a foreboding feeling that my approach is what is B0rK3n. I also > tried mysql_fetch_array and imploding it for a delimited list. No dice. > My query is broken in there somewhere and I'm just not getting it. Fergit it. I figgered it out. Fixed function to list all the tables and their columns: -------------------- $tables = mysql_list_tables($DB); for ($i = 0; $i < mysql_num_rows($tables); $i++) { $tablename = mysql_tablename($tables, $i); echo "| ", $tablename, " |<br>\n"; $fieldlist = mysql_list_fields($DB, $tablename); for ($a = 0; $a < mysql_num_fields($fieldlist); $a++) { $fieldname = mysql_field_name($fieldlist, $a); echo "    |--> $fieldname<br>\n"; } echo "<br><br>\n"; } -------------------- -- QoS rocks harder than Nine Inch Nails at a Lowlands festival, on acid! From: Andy McDowell |