首页 > 解决方案 > mysql 表值合并为一个值而不是多个

问题描述

我的代码遇到了一个问题,这让我很困惑。在下面的代码中,我为要获取的 mysql 数据创建了一个表。但是,当运行我的代码时,所有数据(包括标题、描述和价格)似乎都合并到一个连续的行中,填满了整个页面。我不确定这是否与我试图放入特定行的数据大小有关,或者与我的代码中的错误有关。所以任何帮助将不胜感激。

使用的样式:

    table {
          border: none;
            border-collapse: collapse;
            width: 100%;
            color: #ffffff;
            font-size: 15px;
     }

     th {
         background-color: #a6a6a6;
         color: white;
     }

     table td {
         font-size: 5px;
         border-left: 1px solid #000;
     border-right: 1px solid #000;
     }

     table td:first-child {
     border-left: none;
 }

     table td:last-child {
     border-right: none;
 }

</style>

表和 php:

            <table>
                <tr>
                    <th>Event Title:</th>
                    <th>Event Category:</th>
                    <th>Event Description:</th>
                    <th>Venue:</th>
                    <th>Opening Date:</th>
                    <th>Closing Date:</th>
                    <th>Price:</th>
              </tr>
            </table>
  <?php //Beginig of php script for database events

    include "Database_connection.php"; //Will make the database connection

    $sql = "
SELECT e.eventTitle
     , c.catDesc
     , e.eventDescription
     , v.venueName
     , e.eventStartDate
     , e.eventEndDate
     , e.eventPrice 
  FROM NEE_venue v
  JOIN NEE_events e
    ON e.venueID = v.venueID
  JOIN NEE_category c
    ON c.catID = e.catID
 ORDER 
    BY eventTitle ASC
";
    $queryResult = $dbConn->query($sql);

    if($queryResult === false) { //will detect if the connection failed, and give an error message
        echo "<p>Query failed: ".$dbConn->error."</p>\n</body>\n</html>";
        exit;
      }

      else { //if connection is succsessful, code will retrive the events
        while($row = $queryResult->fetch_assoc()){
          echo "<tr><td>". $row["eventTitle"] ."</td><td>". $row["catDesc"] ."</td><td>". $row["eventDescription"] ."</td><td>". $row["venueName"] ."</td><td>". $row["eventStartDate"] ."</td><td>". $row["eventEndDate"] ."</td><td>". $row["eventPrice"]
                        ."</td></tr>";
        }
                    echo "</table>";
      }
      $queryResult->close();
      $dbConn->close();
      ?>

问题截图:

mysql问题

标签: phpcssmysql

解决方案


去掉顶部的结束表标签。

        <table>
            <tr>
                <th>Event Title:</th>
                <th>Event Category:</th>
                <th>Event Description:</th>
                <th>Venue:</th>
                <th>Opening Date:</th>
                <th>Closing Date:</th>
                <th>Price:</th>
          </tr>
        </table> <---  That one.

从代码和图像看来,数据被打印在表格之外,因为结束表格标签被添加得太早了。


推荐阅读