如何显示我检查过的数据库中的表?

时间:2018-06-29 10:24:49

标签: php mysql database

伙计们。提交时如何显示我检查过的数据库中的表?我不确定我的代码。此代码将仅显示带有复选框的数据库列表,我想要在选中它时显示要检查的数据库表。请帮助

 <?php
 $link = mysqli_connect('localhost','root','');

 $sql = "SHOW databases";
 $result = mysqli_query($link, $sql);

    while ($row = mysqli_fetch_row($result)) {
       $table = $row[0]."<br>";       
 ?>
 <form action="" method="post">
 <input type="checkbox" name="database" value="<?php echo $table;?>"> 
 <?php echo $table?>
 <?php
 }
 ?>
 <input type="submit" name="submit">
 </form>

我几乎明白了。我的新问题是这个。如何放置echo的值以完成查询。或我只是做错了。。

 <?php
 if (isset($_POST['database'])){

 echo $_POST['database'];

 $qry = "show tables from ";    
 $res = mysqli_query($link,$qry);

  while ($row = mysqli_fetch_array($res)){
    echo $row[0]."<br>";
   }
}

2 个答案:

答案 0 :(得分:0)

我认为您的查询是错误的。 假设您的dbname是'mydb',则查询应为... “显示来自mydb的表”。

答案 1 :(得分:0)

 <?php
 $link = mysqli_connect('localhost','root','');

 $sql = "SHOW databases";
 $result = mysqli_query($link, $sql);

    while ($row = mysqli_fetch_row($result)) {
       $table = $row[0];       
 ?>
 <form action = "" method = "post">
 <input type = "checkbox" name = "database" value = "<?php echo $table;?>"> <?php 
 echo $table?>
 <?php
 }
 ?>
 <input type = "submit" name = "submit">
 </form>
 <?php
 if (isset($_POST['database'])){

 $qry = "show tables from ".$_POST['database']; 
 $res = mysqli_query($link,$qry);


 while ($row = mysqli_fetch_array($res)){
    echo $row[0]."<br>";
    }
 }
 ?>