April 21, 2016
Displaying MySQLi Records in a HTML Table

Hi, friends in this tutorial I show you how to display MySQLi records in an HTML Table. Records can be fetched from MySQL tables by executing SQL SELECT statement through PHP function mysql_query we going to display in HTML Table. We have various options to fetch data from MySQL. The most commonly used option is to use function fetch_array(). This function returns rows as an associative array, a numeric array, or both. This function returns TRUE, then the record will execute.
disp.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<?php //Connection for database include 'conn.php'; //Select Database $sql = "SELECT * FROM data"; $result = $conn->query($sql); ?> <!doctype html> <html> <body> <h1 align="center">Employee Details</h1> <table border="1" align="center" style="line-height:25px;"> <tr> <th>Employee ID</th> <th>Name</th> <th>Gender</th> <th>Department</th> <th>Address</th> <th>Mobile Number</th> <th>Email</th> </tr> <?php //Fetch Data form database if($result->num_rows > 0){ while($row = $result->fetch_assoc()){ ?> <tr> <td><?php echo $row['empid']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['gender']; ?></td> <td><?php echo $row['department']; ?></td> <td><?php echo $row['address']; ?></td> <td><?php echo $row['mobile']; ?></td> <td><?php echo $row['email']; ?></td> </tr> <?php } } else { ?> <tr> <th colspan="2">There's No data found!!!</th> </tr> <?php } ?> </table> </body> </html> |
Download
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]