PHP如何从表中获取所有数据并将其相应地放入div中

时间:2017-06-10 16:11:20

标签: php html mysql sql

我在我的数据库中有很多表,并且每个表都有特定的按钮,所以当我点击其中一个按钮时,它应该在div中显示表行和列但是它没有正确显示例如

注意:每个表都有不同的数字列和不同的行数

This is what it looks like
This is what i want, for each of the table

$query = "SELECT * FROM ghousn.$table";
        $result = mysqli_query($connection, $query);
           echo" <table >";
        while($row = mysqli_fetch_assoc($result)){  
            foreach($row as $key => $val){   
               echo "<tr>";
            echo"<th>$key</th> 
          </tr>
          <tr>
            <td>$val</td>


      </tr>";
        }
    }
        echo "</table>";


    }

2 个答案:

答案 0 :(得分:2)

$query = "SELECT * FROM FROM ghousn.$table";
$result = mysqli_query($connection,$query);
echo" <table border='1' >";

 while($row = mysqli_fetch_assoc($result)){  
 echo "<tr>";
     foreach($row as $key => $val){   
       echo"<th>$key</th> ";        
     }
  echo "</tr>";
      echo"<tr>";
     foreach($row as $key => $val){   
       echo "<td>$val</td>";        
     }
     echo "</tr>";
 }

echo "</table>";

答案 1 :(得分:0)

试试这个

$query = "SELECT * FROM ghousn.$table";
$result = mysqli_query($connection, $query);
echo" <table >";

while($row = mysqli_fetch_assoc($result)){  
echo "<tr>";
    foreach($row as $key => $val){   
      echo"<th>$key</th> 
            </tr>
            <tr>
            <td>$val</td>";

    }
  echo "</tr>"
}

echo "</table>";
相关问题