Guys in this tutorial I will explain you how to fetch values from the database and show those in a Table format.
Here I assumed one thing, that the user is logged in. and that user has the rights to delete a particular record from the table.
NOTE: This tutorial is very old. But will glimpse you how you can format your data in a structured manner.
So are you Guys Ready???? Then Let’s Start……..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
session_start(); | |
if (!isset($_SESSION['username'])) { | |
header("Location: login.php"); | |
} | |
?> |
Note: This will start the session of that particular user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php$con = mysql_connect("localhost", "USERNAME", "PASSWORD"); | |
if (!$con) { | |
die('Could Not Connect: ' . mysql_error()); | |
} | |
mysql_select_db("DB_NAME", $con); | |
$result = mysql_query("SELECT firstname, lastname, email, phone, mobile, address_1, address_2, city, zipcode, country, state FROM TABLE_NAME"); | |
echo " | |
<table border='1'> | |
<tr> | |
<th>S. NO. </th> | |
<th>First Name</th> | |
<th>Last Name</th> | |
<th>Email Address</th> | |
<th>Phone No.</th> | |
<th>Mobile No.</th> | |
<th>Address</th> | |
<th>City & Zip</th> | |
<th>State & Country</th> | |
<th> Delete Entry</th> | |
</tr>"; | |
$i = 1; | |
while($row = mysql_fetch_array($result)) | |
{ | |
echo "<tr>"; | |
echo "<td>" . $i . "</td>"; | |
echo "<td>" . $row['firstname'] . "</td>"; | |
echo "<td>" . $row['lastname'] . "</td>"; | |
echo "<td>" . $row['email'] . "</td>"; | |
echo "<td>" . $row['phone'] . "</td>"; | |
echo "<td>" . $row['mobile'] . "</td>"; | |
echo "<td>" . $row['address_1'] . ", " . $row['address_2'] . "</td>"; | |
echo "<td>" . $row['city'] . ", " . $row['zipcode'] . "</td>"; | |
echo "<td>" . $row['state'] . ", " . $row['country'] . "</td>"; | |
echo "<input type='hidden' name='mobile' value='$row[mobile]' />"; | |
echo "<td>" . "<input type='submit' name='submit' value='Delete'/>" . "</td>"; | |
echo "</tr>"; | |
$i++; | |
} | |
echo "</table>"; | |
mysql_close($con); | |
?> |