My crappy code

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2004
Handover Phist
 
Posts: n/a
Default My crappy code

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
Reply With Quote
  #2 (permalink)  
Old 01-16-2004
Handover Phist
 
Posts: n/a
Default Re: My crappy code

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 "&nbsp &nbsp |--> $fieldname<br>\n";
}
echo "<br><br>\n";
}
--------------------
--
QoS rocks harder than Nine Inch Nails at a Lowlands festival, on acid!
From: Andy McDowell
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0