how to fetch data from database in php and display in table, fetch data from database and display in html table

First, connect to a MySQL database. Check it out the connecting to MySQL database using PDO tutorial for detail information. Then, construct a SELECT statement and execute it by usingĀ the query() method of the PDO object. The query() method of the PDO object returns a PDOStatement object, or false on failure.

 

Select query php code –

              <table width="100%" cellspacing="0">
                  <thead>
                    <tr>
                      <th style='display:none;'>SL No.</th>
                      <th class='text-primary'>Employee id</th>
                      <th class='text-primary'>Employee Name</th>
                      <th class='text-primary'>Employee ID Card<br>Scale->Custom:190</th>
                      <th class='text-primary'>Employee ID Validity<br>Scale->Custom:90</th>
                      <th class='text-primary'>Employee Data Remove</th>
                    </tr>
                  </thead>
                  <tbody>
<?php
//$mobile = $_POST['mobile'];
$mobile = "87348767687XX"
$query = "select * from employeedata  where employeemobileno='$mobile'";
$data = mysqli_query($connection,$query);
$total = mysqli_num_rows($data);

if($total!=0){
	
	
	while($row = mysqli_fetch_assoc($data)){



		      echo "<tr>
                      <td style='display:none;'>".$sl."</td>
					  <td style='font-size:15px' class='text-primary'>".strtoupper($row['employeeid'])."</td>
					   <td style='font-size:13px' class='text-primary'>".strtoupper($row['employeename'])."</td>
                      <td><a href = 'download.php?epic_no=$row[employee_no]&token=$row[employeeid]' target='_blank'><b>Print<b></td>
					  <td style='font-size:13px' class='text-primary'>".strtoupper($row['employeevalidity'])."</td>
					  <td><a href = 'epiccarddelete.php?id=$row[employeeid]' onclick='return deleteItem()'><b style='color:red'>Delete</b></td>
                      
                    </tr>";
$sl++;
}
}
?>	
				
                  </tbody>
                </table>
 <script>
function deleteItem() {
return confirm("Are you sure you want to delete this record ?");
};
</script>
HTML

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *