【问题标题】:How to display PHP function output in a single column of a table vertically?如何在表格的单列中垂直显示 PHP 函数输出?
【发布时间】:2020-10-19 15:02:04
【问题描述】:

如何在带有左侧垂直标题的表格中显示给定 PHP 函数的输出,如图所示?代码中给出了标题名称,我只需要一个带有 PHP 结果的数据列。提前致谢。 此代码用于标题水平表-

<div class="container">
<form action="" method="POST">
<input type="text" name="id" class="btn" placeholder="Enter Lab Number"> 
<input type="submit" name="search" class="btn" value="SEARCH">

</form>

<table>

  <tr>
 <th> Lab number </th>
<th> First name </th>
<th> Middle name </th>
<th> Last name </th>
<th> Gender </th>
<th> Date of birth </th>
<th> Permanent address </th>

  </tr>


<br>

<?php 
......  ?>
            <tr>
                <td> <?php echo $row['lab_number']; ?> </td>
                <td> <?php echo $row['p_first_name']; ?> </td>
                <td> <?php echo $row['p_middle_name']; ?> </td>
                <td> <?php echo $row['p_last_name']; ?> </td>
                <td> <?php echo $row['gender']; ?> </td>
                <td> <?php echo $row['dob']; ?> </td>
                <td> <?php echo $row['address']; ?> </td>
            </tr>
            
            <?php
    }
     
}
?>
</table>
</div>

【问题讨论】:

  • 什么图像和什么功能?你能更好地解释你的问题吗?
  • 图片在问题的开头显示为 --image-- 我需要的页面功能是搜索具有已知id的数据库记录。
  • 到目前为止你尝试了什么?
  • 警告!您对SQL injection 攻击敞开大门!您应该使用参数化的prepared statements,而不是像这样直接在查询中使用完全未转义的用户数据。 永远永远永远相信用户输入。

标签: php


【解决方案1】:

我认为你的预期输出是这样的.....

table{
  text-align:left
  }
<div class="container">
<form action="" method="POST">
<input type="text" name="id" class="btn" placeholder="Enter Lab Number"> 
<input type="submit" name="search" class="btn" value="SEARCH">

</form>

<table>
<?php 
$connection = mysqli_connect("localhost","root","");
$db = mysqli_select_db($connection,'web_a');

if(isset($_POST['search']))
{
    $id = $_POST['id'];
    
    $query = "SELECT * FROM `lab_results` where lab_number='$id' ";
    $query_run = mysqli_query($connection,$query);
    
    while($row = mysqli_fetch_array($query_run))
    {
            ?>
              <tr>
                <th> Lab number </th>
                <td> <?php echo $row['lab_number']; ?> </td>
              </tr>
              <tr>
                <th> First name </th>
                <td> <?php echo $row['p_first_name']; ?> </td>
              </tr>
              <tr>
                <th> Middle name </th>
                <td> <?php echo $row['p_middle_name']; ?> </td>
              </tr>
              <tr>
                <th> Last name </th>
                <td> <?php echo $row['p_last_name']; ?> </td>
              </tr>
              <tr>
                <th> Gender </th>
                <td> <?php echo $row['gender']; ?> </td>
              </tr>
              <tr>
                <th> Date of birth </th>
                <td> <?php echo $row['dob']; ?> </td>
              </tr>
              <tr>
                <th> Permanent address </th>
                <td> <?php echo $row['address']; ?> </td>
              </tr>
            
            <?php
    }
     
}
?>
</table>
</div>

【讨论】:

  • 谢谢兄弟。你可以编辑你的回复删除不需要的部分吗?你觉得问题中有更多需要删除的部分吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
相关资源
最近更新 更多