How to display mysql table column headers using php ?

,


Step 1:

Create data base connection

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "search";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);


Step 2:

Select the table

$sql = "Select * from keywords"; 

Step 3:

Get the table header values from database

$result=mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($result);
$x = array_keys($row);

Step 4:

Print the headers value

foreach($x as $rows)
{
 print $rows.'<br >';
}

Final Code:


<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "search";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
 
$sql = "Select * from keywords"; 

$result=mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($result);
$x = array_keys($row);

foreach($x as $rows)
{
 print $rows.'<br >';
}
 

?>





Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.