lang="en-US"> PHP Tutorial: Print All MySQL Database Tables & Fields –  Design1online.com, LLC

PHP Tutorial: Print All MySQL Database Tables & Fields


            
                " . $table[0] . "
            
            
                Field
                Type
                Key
                Default
                Extra
            ";

    $i = 0; //row counter
    $row = mysql_query("SHOW columns FROM " . $table[0])
    or die ('cannot select table fields');

    while ($col = mysql_fetch_array($row))
    {
        echo "
            " . $col[0] . "
            " . $col[1] . "
            " . $col[2] . "
            " . $col[3] . "
            " . $col[4] . "
        ";

        $i++;
    } //end row loop

    echo "

"; } //end table loop ?>

You may also like...

13 Responses

  1. Jaiganesh says:

    Hi, Nice one. thanks. And with your permission i can get this details from my site. And give your reference link for this url.

    Are you giving permission to do this. I have no more english language.

    thanks,
    J.

  2. Jade says:

    Sure you can use this on your website, just leave my domain name at the top of the code.

  3. jwzumwalt says:

    There is an additional column that can be shown. The updated listing is shown here.

    /*
    +………………………………………..+
    : show table structure :
    +………………………………………..+ */
    $database = “test_db”;
    $loop = mysqli_query($db, “SHOW tables FROM $database”) or die (‘cannot select tables’);

    while($table = mysqli_fetch_array( $loop)) {
    echo ”

    ” . $table[0] . ” table structure

    Field
    Type : Length
    Key
    Index
    Default
    Extra
    “;

    $i = 0; //row counter
    $row = mysqli_query($db, “SHOW columns FROM ” . $table[0])
    or die (‘cannot select table fields’);

    while ($col = mysqli_fetch_array($row)) {
    echo ”
    ” . $col[0] . ”
    ” . $col[1] . ”
    ” . $col[2] . ”
    ” . $col[3] . ”
    ” . $col[4] . ”
    ” . $col[5] . ”
    “;

    $i++;
    } //end row loop

    echo “”;
    } //end table loop

  4. Took pieces from this code, Thanks!

  5. funckytown says:

    hi,
    I was just wandering,
    how many columns can we add?
    how does the loop knows from $col ?

    thx in adb=vance,

    • Jade says:

      You can add up to count($col) columns to the list. If you always want to print all of them you can change the code inside of the while ($col = mysql_fetch_array($row)) to the following:


      while ($col = mysql_fetch_array($row))
      {
      echo "<tr>";

      //print the whole array returned in $col
      for ($j = 0; $j < count($col); $j++)
      echo "<td>{$col[$j]}</td>";

      echo "</tr>";

      $i++;
      } //end row loop

  6. funckytown says:

    thanx, it works nice,

  7. Frank says:

    That’s a great, cute script ! No need to go into cPanel / phpadmin anymore ! But now; Do you have any sample to print certain db-field contents just like an address book, such as this ?:

    Name Surname Tel.no. e-mail address
    ————————————————————————————
    Peter Baker 0123 45678 peter&baker.com

    The script that I “created” prints it all, but not formatted, with certain distance between the fields. I don’t find a way how to format the headline and then underneath the content of the db equally. Sorry, PHP knows me perhaps, but I don’t know much about PHP….

    Thanks for any advise,if you have

  8. Raghavendra says:

    How can we display data of each table?

  9. karma says:

    0) {
    while ($row = mysqli_fetch_assoc($result)) {
    echo ($row);
    }
    }
    ?>

  10. karma says:

    above code fails; why? need help;
    karma

Leave a Reply