简体   繁体   中英

I am doing this code in php while selecting any database it only display the number of tables not the names of all tables of the selected database

<?php
    session_start();`enter code here`
    include 'dbconnect.php';

    $q=$_GET['q'];

    echo $field= "Tables_in_".$q;

    $sql = "SHOW TABLES FROM $q";

    $result= mysqli_query($conn,$sql);

     $new= array();
     $i=0;

    while ($row=mysqli_fetch_row($result)){
        echo $row['Tables_in_mysql'];

        $new[$i]=$row;
        $i++;
    }
    echo $num=count($new);
?>

<?php
    for($j=0;$j<$num;$j++){
        echo "here"; 
?>   

<?php echo $new[$j]['mysql']; ?>

<?php } ?>
<?php echo $q;?>

<?php
    session_start();`enter code here`
    include 'dbconnect.php';

    $q=$_GET['q'];

    echo $field= "Tables_in_".$q;

    $sql = "SHOW TABLES FROM $q";

    $result= mysqli_query($conn,$sql);

     $new= array();
     $i=0;

     while ($row=mysqli_fetch_row($result)){

        echo $row['Tables_in_mysql'];

        $new[$i]=$row;
        $i++;

    }
    echo $num=count($new);

?>

<?php for($j=0;$j<$num;$j++){      

    echo "here"; 
?>   


<?php echo $new[$j]['mysql'];   ?>

<?php } ?>
<?php echo $q;?>

This is my code please help me in printing all the names of the tables of the selected database in php I have shown all the names of the database by show database command and it is displaying in a dropdown and while selecting particular database it only displays the number of the tables in it but i want to display names of tables

As you did not post any code this answer is perhaps not what you were after... but this will display all the tables in the current database.

select `table_name` as 'table' 
    from `information_schema`.`tables` 
    where `table_type`='base table' and `table_schema`=database();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM