Sanjeewa
Sanjeewa

Reputation: 13

How to display PHP function output in a single column of a table vertically?

image2

How can I display the output of the given PHP function in a table with the left vertical headers, as given in the image? Header names are given in the code and I need only one data column with PHP result. Thanks in advance. This code is for headers horizontal table-

<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>

Upvotes: 0

Views: 64

Answers (1)

Muhammad Kamran
Muhammad Kamran

Reputation: 151

I think your expected output like this.....

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>

Upvotes: 1

Related Questions