SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    listing tables from a db??

    Can anyone tell me how can I list the table names from a database ??

    I tried doing it but failed. By the way I want the table name to appear in a drop down list.

    Thanks in advance


    -Omair
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  2. #2
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, I tried using this code but all it does is displays the same table twice.

    BTW, there is only one table in the database.

    Anyways here is the code:

    PHP Code:
    <?php
    $host
    ="localhost";
    $username="";
    $password="";
    $database="jokeave";


    $list mysql_list_tables($database); 
    $result mysql_fetch_array($list)
    ?>

    <select name="select">
    <?php
    do {
    $val=current($result);
    echo 
    "<option>$val</option>";
    } while (
    next($result));
    ?>
    </select>
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  3. #3
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <select name="select">
    <?php
    $query 
    mysql_list_tables("databasename");

    for (
    $i=0$i mysql_num_rows($query);) {
            
    $result mysql_tablename($query$i++);
            echo 
    "<option>$result\n";
    }
    ?>
    </select>

  4. #4
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this,
    PHP Code:
    $list=mysql_list_tables($database); 
    while ( list(
    $name) = mysql_fetch_array($list)) {
      echo 
    "$name<br>";


  5. #5
    SitePoint Evangelist AlexC's Avatar
    Join Date
    Oct 2000
    Location
    Sheffield, UK
    Posts
    437
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i had to write a script recently which loops through a database, gets the tablenames and lists below it the fields in the table

    PHP Code:
    <?php
    mysql_connect
    ("localhost","xxxxxx","xxxxxxx");
    $DB "hanswer_forums";
    mysql_select_db($DB); 
    $tables=mysql_list_tables($DB); 
    while (list(
    $bla)=mysql_fetch_array($tables)) 
    {
    echo 
    "<br><font face=verdana,arial size=2><b>Table: $bla</b>";
    echo 
    "<br>";
    $fields mysql_list_fields("$DB""$bla");
    $columns mysql_num_fields($fields);

    for (
    $i 0$i $columns$i++) {
        echo 
    mysql_field_name($fields$i) . "<br>";;
    }

    }
    ?>
    Hope this helps,
    Alex


Bookmarks

Posting Permissions

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