php - 垂直显示表格

标签 php html css mysql

我想垂直显示表格。现在,它是水平显示的。每个 每个字段都在显示。如何垂直显示表格? 还有一件事我想给按钮再添加一个功能。当前的 按钮时添加到数据库中的日期 提交被点击。现在这段代码使我的状态为 0 并且不更新 数据库中的日期。

<html>
    <head>
        <meta name="description" content="website description" />
        <meta name="keywords" content="website keywords, website keywords" />
        <meta http-equiv="content-type" content="text/html; charset=windows-
            1252" />
        <link rel="stylesheet" type="text/css" href="style/style.css" />
        <style>
            <table>
            {
            border-style:solid;
            border-width:2px;
            border-color:pink;
            }
        </style>
    </head>
    <?php
        include 'inc/head.php';

        include 'connection.php';

        $id = $_GET['id'];

        $sql = "SELECT * FROM user WHERE id='$id'";

        $query = mysqli_query($conn, $sql);

        echo "<table border='6'>
          <tr>
              <th>Application Type</th> <br>
              <th>First name</th><br>
              <th>Sur name</th><br>
              <th>title</th>
              <th>Date of Birth</th>
              <th>Gender</th>
              <th>Nationality</th>
              <th>Country of Birth</th>
              <th>Applicant's Location</th>
              <th>alias</th>
              <th>Criminal </th>
              <th>Country of passport</th>
              <th>Passport number</th>
              <th>Passport issue date </th>
              <th>Passport expiry date</th>
              <th>Address </th>
              <th>City</th>
              <th>State</th>
              <th>Postal Code</th>
              <th>Country</th>
              <th>Email Address</th>
              <th>Home Number</th>
              <th>Business Number</th>
              <th>mobile</th>
          </tr>";

        while($row = mysqli_fetch_assoc($query)) {
            echo "<tr>";
            echo "  <td>" . $row['applicationtype'] . "</td>";
            echo "  <td>" . $row['firstname'] . "</td>";
            echo "  <td>" . $row['lastname'] . "</td>";
            echo "  <td>" . $row['title1'] . "</td>";
            echo "  <td>" . $row['dob'] . "</td>";
            echo "  <td>" . $row['gender'] . "</td>";
            echo "  <td>" . $row['nationality'] . "</td>";
            echo "  <td>" . $row['countryofbirth'] . "</td>";
            echo "  <td>" . $row['applicantlocation'] . "</td>";
            echo "  <td>" . $row['alias'] . "</td>";
            echo "  <td>" . $row['criminal'] . "</td>";
            echo "  <td>" . $row['countryofpassport'] . "</td>";
            echo "  <td>" . $row['passportnumber'] . "</td>";
            echo "  <td>" . $row['pid'] . "</td>";
            echo "  <td>" . $row['ped'] . "</td>";
            echo "  <td>" . $row['address'] . "</td>";
            echo "  <td>" . $row['city'] . "</td>";
            echo "  <td>" . $row['state'] . "</td>";
            echo "  <td>" . $row['postalcode'] . "</td>";
            echo "  <td>" . $row['country'] . "</td>";
            echo "  <td>" . $row['email'] . "</td>";
            echo "  <td>" . $row['homephone'] . "</td>";
            echo "  <td>" . $row['businessphone'] . "</td>";
            echo "  <td>" . $row['mobile'] . "</td>";




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

        if(isset($_POST['submit'])) {
            echo $radio = $_POST['radio'];
            $date_clicked = date('Y-m-d H:i:s');

            $sql = "UPDATE user SET visastatus='$radio' AND currentdate='$date_clicked' WHERE id='$id'";
            $query = mysqli_query($conn, $sql);
            if($query) {
                echo "<h4 style='color:green'>Action Performed Successfully....</h4>";
            } else {
                echo "<h4 style='color:red'>Failed.</h4>";
            }
        }
    ?>
        <form method="POST" action="" enctype="multipart/form-data">
            <div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" style="margin-top: 
                8px;">
                <label class="checkbox-inline tourist-rad">
                <input type="radio" name="radio" id="success" 
                    value="Successfull">Successfull
                </label>            
                &nbsp;&nbsp;&nbsp;
                <label class="checkbox-inline tourist-rad">
                <input type="radio" name="radio" id="decline" value="Declined">Declined
                </label>
                &nbsp;&nbsp;&nbsp;
            </div>
            <div class="form-group">
                <button type="submit"  name="submit"  value="submit" class="btn btn-
                    primary" style="float: right;">Update Menu Item</button>
            </div>
    </body>
</html>

最佳答案

How can I display the table vertically?

将每个标题放在新的 <tr> 中.记住,<tr>代表表格行,而<td>适用于该行中的每个元素。这将需要对您的 php 代码进行一些修改,以便您基本上可以打印一个新行,以及其中的每个 td。

编辑:要根据需要垂直显示它,您需要修改现有的 while 循环。

//Print the row
echo "<tr>";

//Print the row heading
<th>Application Type</th>
while($row = mysqli_fetch_assoc($query)) {
        //Print each matching data type inside
        echo "  <td>" . $row['applicationtype'] . "</td>";

}
//Close the row
echo "</tr>";

您需要为您拥有的每个标题执行此功能。您还可以使用数组和嵌套循环来干净、轻松地打印所有数据,而无需多余的代码。

关于php - 垂直显示表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46002034/

相关文章:

html - 菜单隐藏在 div 中

php - paypal支付成功后重定向到一个页面

php - Codeigniter 路线与方法和编辑

javascript - 从数据库填充下拉框而不重新加载页面

javascript - 如何通过单击另一个 <td> 中的超链接来打开表 <td> 中的页面

javascript - 选定的行具有悬停状态

html - 使用文档片段的 anchor 元素的 CSS 选择器

css - Ionic 5 在 iOS 上设置可折叠标题颜色

html - 试图将我自己的插入符号图标放在自定义下拉列表中

PHP 自动加载 : Preventing 'cannot redeclare <class>' in all constellations?