twitter-bootstrap 引导程序在表中显示来自 mysql 的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36967981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:53:21  来源:igfitidea点击:

bootstrap display data from mysql in table

phphtmlmysqltwitter-bootstrap

提问by swipeales

I am trying to display my mysql rows to html bootstrap table. Database connection is working, displaying data is working, but it is not fancy as i want. I'd like to maybe save in arrayData maybe and then print this arrayData in html tag. Please any suggestions much appreciated. I want to do this easiest way and most convenient for editing later on. php code to display data :

我正在尝试将我的 mysql 行显示到 html bootstrap 表。数据库连接正在工作,显示数据正在工作,但它并不像我想要的那样花哨。我想也许可以保存在 arrayData 中,然后在 html 标签中打印这个 arrayData。请提供任何建议,非常感谢。我想用这种最简单的方法,也最方便以后进行编辑。显示数据的php代码:

    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["lastName"]. "<br>"; /* and so on..*/
    }
} else {
    echo "0 results";
}

and this is my html code for bootstrap

这是我的引导程序的 html 代码

    <table class="table table-striped">                     
<div class="table responsive">

  <thead>
    <tr>
      <th>#</th>
      <th>Name</th>
      <th>Last Name</th>
      <th>Number</th>
       <th>Info</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>ales</td>
      <td>king</td>
      <td></td>
        <td></td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>love</td>
      <td>2</td>
      <td>code</td>
        <td></td>
    </tr>

  </tbody>
        </div>
   </table>

EDIT: i want this, but loaded from database not manually typed :)!

编辑:我想要这个,但是从数据库加载而不是手动输入:)!

enter image description here

在此处输入图片说明

回答by scaisEdge

You can use a php loop this way

您可以通过这种方式使用 php 循环

<table class="table table-striped">                     
    <div class="table responsive">
        <thead>
            <tr>
              <th>#</th>
              <th>Name</th>
              <th>Last Name</th>
              <th>Number</th>
               <th>Info</th>
            </tr>
        </thead>
        <tbody>
<?php 

....

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {


        echo '<tr>
                  <td scope="row">' . $row["id"]. '</td>
                  <td>' . $row["name"] .'</td>
                  <td> '.$row["lastName"] .'</td>
                </tr>';





    }
} else {
    echo "0 results";
} 
?>
       </tbody>
    </div>
</table>

回答by Neko

I would do something like this: ( but you should really read some basic PHP )

我会做这样的事情:(但你真的应该阅读一些基本的 PHP )

<?php

echo "<table>";

// table header
echo "<tr><th>id</th><th>Name</th><th>Lastname</th></tr>";

// output data of each row
while($row = $result->fetch_assoc()) {

    echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["lastName"]."</td></tr>";
}

// table footer

echo "</table>";

?>