【问题标题】:I am trying to display information in a table format from sql database what am I doing wrong?我正在尝试从 sql 数据库中以表格格式显示信息我做错了什么?
【发布时间】:2015-03-14 01:34:47
【问题描述】:

好的,我可以将数据库中的数据显示到页面上,但是我在以表格格式很好地显示它时遇到了问题,因此它位于标题下方并位于页面下方。这是目前发生的事情:

这是我的页面代码:

<link rel="stylesheet" href="css/productiontable.css">
<?php
error_reporting(0);
require './db/connect.php';
include './includes/header.php'; 

?>
<h2>Productions</h2>

<div class="productiontable">
    <table>
        <tr>
            <th>Production Name</th>
            <th>Production Description</th>
            <th>Production Type</th>
        </tr>
        <tr>
            <td class="productname">
                <?php 
                    if($result = $connection->query("SELECT * FROM Production")){
                        if($count = $result->num_rows){

                            while($row = $result->fetch_object()){
                                echo $row->ProductionName; 


                ?>
            </td>
            <td class="productinfo">
                <?php 

                                echo $row->ProductionInformation;

                ?>
             </td>
             <td class="producttype">
                <?php 

                                echo $row->ProductionType;

                            }
                ?>
            </td><bR>
         </tr>

    </table>
                <?php
                $result->free();
                        }
                    }
    mysqli_close($connection);


include './includes/footer.php';

这是表格的css:

@import url(http://fonts.googleapis.com/css?family=Dosis);

h2{
    text-align: left;
    color: white;
    font-family: 'Dosis';
    margin: 10px;
    font-size: 32px;
}
h3{
    font-size: 18px;
    color: white;
    margin: 20px; 
}
.productiontable{
    width: 900px;
    border: 1px black solid;
    margin: 10px;
}
.productname{
    width: 200px;
    float: left;
    font-weight: bold;
    margin-left: 10px;
 }
.productinfo{
    width: 500px;
    float: left;
    margin-left: 10px;
 }
 .producttype{
    width: 200px;
    float: left;
    font-style: oblique;
    margin-left: 10px;
  }

请尽可能多的帮助非常感谢:)

【问题讨论】:

  • 你的循环控制放错了地方。它需要在 TR 之外。
  • 表格单元格不需要浮动,它们不能有边距,只有填充。最重要的是,您可以将它们垂直对齐到顶部vertical-align: top;
  • @DavidSoussan 非常感谢你现在开始工作了 :)
  • @Caelea 非常感谢你让它工作:)

标签: php html mysql css


【解决方案1】:

有几个问题: 1. 不需要 br 标签。 2.循环应该在tr之外。这样每行都会创建一个新行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2010-12-03
    相关资源
    最近更新 更多