help me to fetch mysql databse field to seprate link,

when i was using this code 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)) { ?>
  • Name:<?php echo $row['name'];?>

  • gender:<?php echo $row['gender'];?>

  • Address:<?php echo $row['address'];?>

  • Back
<?php }{ die(mysql_error()); }

?>,
when i got output like this below

1 Name:laya

gender:male

Address:dfdgdfhgtfhjgfj
Back

2 Name:fara

gender:female

Address:thrissur
Back

3 Name:raju

gender:male

Address:kuttuuuuuuuur
Back

but,actually i want to display each data by seperate link
based on the employee detail
like

employee1
employee2
employee3
employee4

plzz help me to fetch the data to separate link

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.

You are using deprecated code. You need to use PDO or Mysqli.

Sponsor our Newsletter | Privacy Policy | Terms of Service