Your phrasing is a bit confusing. I’m guessing you want a link to a page for each employee instead of listing all their details on one page?
Maybe this will help.
employees.php
(This page will grab all “employees” and link to them using their IDs)
[php]<?php
session_start();
mysql_connect(“localhost”,“root”,"");
mysql_select_db(‘employee’);
$query=“SELECT * FROM employee”;
$r=mysql_query($query);
while($row=mysql_fetch_array($r)) {
$id = $row[‘id’];
?>
Employee <?php echo $id; ?>
<?php
}{
die(mysql_error());
}
?>[/php]
employee.php
(This page will retrieve the ID from the link that was clicked on “employees.php”, plug that ID into the database, and pump out the details for that employee)
[php]<?php
session_start();
if (isset($_GET[‘id’])){ $id = $_GET[‘id’]; }
mysql_connect(“localhost”,“root”,"");
mysql_select_db(‘employee’);
$query=“SELECT * FROM employee WHERE id=”.$id."";
$r=mysql_query($query);
while($row=mysql_fetch_array($r)) {
$name = $row[‘name’];
$gender = $row[‘gender’];
$address = $row[‘address’];
?>
Name:<?php echo $name; ?>
gender:<?php echo $gender; ?>
Address:<?php echo $address; ?>
-
- Back
<?php
}{
die(mysql_error());
}
?>[/php]
Just a friendly tip, you should be more careful about the names you pick. You’re using “employee” for both the database name and a table name. Whatever company you’re building this for, I’d suggest renaming the database name to that, or an abbreviation, or an acronym of their name. And I’d change the table name from “employee” to “employees” because that table will be holding multiple employees.