Skip to content

Instantly share code, notes, and snippets.

@jeggu96
Last active April 27, 2017 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeggu96/8782a5bfcec1244a211e7f8193d2ea86 to your computer and use it in GitHub Desktop.
Save jeggu96/8782a5bfcec1244a211e7f8193d2ea86 to your computer and use it in GitHub Desktop.
This PHP code is used to display the table content from the DB into a table in HTML
<?php
define("DB_HOST","localhost");//DB HOST NAME
define("DB_NAME","login");// DB NAME
define("DB_USERNAME","root");// DB USERNAME
define("DB_PASSWORD","");// DB PASSWORD
$conn=@mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME); // CONNECT TO THE DB
$query="SELECT * from users"; // SQL QUERY TO SELECT ALL THE COLUMNS OF THE TABLE
$response =@mysqli_query($conn,$query);// GET RESPONSE FROM THE DB
if($response){ // IF RESPONSE IS TRUE
echo '<table align="left" cellpadding="5" cellpadding="8" border="1">
<tr><td align="left"><b>username</b></td>
<td align="left"><b>password</b></td>
<td align="left"><b>regno</b></td>
<td align="left"><b>name</b></td></tr>';
while($row=mysqli_fetch_array($response)){
echo '<tr><td align="left">'.
$row['username'] . '</td><td align="left">'. // DISPLAY THE COLUMN WITH NAME USERNAME
$row['password'] . '</td><td align="left">'. // DISPLAY THE COLUMN WITH NAME PASSWORD
$row['regno'] . '</td><td align="left">'. // DISPLAY THE COLUMN WITH NAME REGISTER #
$row['name'] . '</td>'; // DISPLAY THE COLUMN WITH NAME NAME
echo '</tr>';
}
echo '</table>';
} else{ // IF RESPONSE IS FALSE
echo "error";
echo mysqli_error($conn); // DISPLAY THE ERROR
}
mysqli_close($conn); // CLOSE THE DB CONNECTION
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment