My crappy code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Handover Phist

    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_tabl es($DB);
    for ($i = 0; $i < mysql_num_rows( $tables); $i++) {
    $tablename = mysql_tablename ($tables, $i);
    echo "Table: ", $tablename, "<br><br>\n ";

    $fieldlist = mysql_field_nam e($DB, $tablename);
    for ($a = 0; $a < mysql_num_field s($fieldlist); $a++) {
    $fieldname = mysql_fetch_fie ld($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_arr ay 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

    #2
    Re: My crappy code

    Handover Phist blithely blithered[color=blue]
    > 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_tabl es($DB);
    > for ($i = 0; $i < mysql_num_rows( $tables); $i++) {
    > $tablename = mysql_tablename ($tables, $i);
    > echo "Table: ", $tablename, "<br><br>\n ";
    >
    > $fieldlist = mysql_field_nam e($DB, $tablename);
    > for ($a = 0; $a < mysql_num_field s($fieldlist); $a++) {
    > $fieldname = mysql_fetch_fie ld($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_arr ay and imploding it for a delimited list. No dice.
    > My query is broken in there somewhere and I'm just not getting it.[/color]

    Fergit it. I figgered it out. Fixed function to list all the tables and
    their columns:
    --------------------
    $tables = mysql_list_tabl es($DB);

    for ($i = 0; $i < mysql_num_rows( $tables); $i++) {
    $tablename = mysql_tablename ($tables, $i);
    echo "| ", $tablename, " |<br>\n";

    $fieldlist = mysql_list_fiel ds($DB, $tablename);

    for ($a = 0; $a < mysql_num_field s($fieldlist); $a++) {
    $fieldname = mysql_field_nam e($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

    Comment

    Working...