如何使用bootstrap css表来显示MySQL表中的数据? [英] How to use bootstrap css tables to display data from MySQL tables?

查看:317
本文介绍了如何使用bootstrap css表来显示MySQL表中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做,当我的主页面上点击一个按钮,php脚本采取行动,从SQL表中提取信息,并显示在一个HTML / CSS表。

I'm trying to make it so that when a button is clicked on my main page, a php script takes action and fetches the information from the SQL tables, and displays it in a HTML/CSS table.

这是主页的代码 -

Here's the code of my main page -

<form id="myForm" action="select.php" method="post">
<button type="submit" class="btn btn-info" >
<span class="glyphicon glyphicon-tint"></span>  View
</button>
<br /> <span class="badge alert-info"> Find out what is currently in the database. </span><br />
</form>
<br />
<br />  

这里是我目前在select.php -

And here's what I currently have in my select.php -

<?php
/*** mysql hostname ***/
$hostname = '192.xx.xxx.xx';

/*** mysql username ***/
$username = 'Mitchyl';

/*** mysql password ***/
$password = 'root1323';

/*** database name ***/
$dbname = 'test';

try {
      $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
    /*** The SQL SELECT statement ***/
    $sql = "SELECT * FROM increment";

}
catch(PDOException $e)
    {
    echo $e->getMessage();
    }
?>

我不知道如何从SQL查询中获取数据,表。

I just don't know how to take the data from the SQL query and put it inside a HTML table.

任何建议都会很棒!
谢谢!

Any suggestions would be great! Thanks!

推荐答案

试试这个

<?php
  $hostname = '192.xx.xxx.xx';
  $username = 'Mitchyl';
  $password = 'root1323';
  $dbname = 'test';

  try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);

    $sql = $dbh->prepare("SELECT * FROM increment");

    if($sql->execute()) {
       $sql->setFetchMode(PDO::FETCH_ASSOC);
    }
  }
  catch(Exception $error) {
      echo '<p>', $error->getMessage(), '</p>';
  }

?>

  <div id="content">

    <table>
      <?php while($row = $sql->fetch()) { ?>
      <tr>
        <td><?php echo $row['column1_name']; ?></td>
        <td><?php echo $row['column2_name']; ?></td>
        <td><?php echo $row['column3_name']; ?></td>

        ...etc...

      </tr>
      <?php } ?>
    </table>

   </div>

这篇关于如何使用bootstrap css表来显示MySQL表中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆