Results 1 to 3 of 3

Thread: [RESOLVED]How to output tablenames in specific databae using php

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    [RESOLVED]How to output tablenames in specific databae using php

    hi all. Could any one show me how to display table names of a specific database using php? I tried the following but didn't output any thing!!

    PHP Code:
    <?php

    $server   
    "localhost"// MySQL hostname
    $username "root"// MySQL username
    $password "?????"// MySQL password
    $dbname   "kingkong"// MySQL db name

    $db mysql_connect($server$username$password) or die(mysql_error());
          
    mysql_select_db($dbname) or die(mysql_error());

    $sql "SHOW TABLES FROM kingkong ";

    $fp fopen("query.txt""w");
    fwrite($fp$sql);
    fclose($fp);      
    $result mysql_query$sql );

    while(
    $row = @mysql_fetch_array($result)) {

    ?>
    <?php 
    echo $row["tables"?>

    <?

    }

    ?>
    Last edited by tony007; Oct 27th, 2007 at 12:10 PM.

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: How to output tablenames in specific databae using php

    'tables' isn't the field name that is returned by SHOW TABLES it's 'Tables_in_DBNAME'

    so use $row[0]; or $row['Tables_in_kingkong'];
    Chris

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to output tablenames in specific databae using php

    thanks that $row[0] fixed it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width