<html>
<head script type="javascript/text">
<script>
function validate()
{

var html=document.getElementById(<?php '$count1'?>);
<?php
session_start();
$_SESSION['fuserid']=?>="html"

}
</script>
</head>
</html>
<?php
session_start();

$database="myfriend";
$userid=$_SESSION['user'];
mysql_connect("127.0.0.1","root","");
$db_found=mysql_select_db($database);
$sql="select fuserid from friends where userid='$userid';";
$result=mysql_query($sql);
$count1=0;
while($db_field=mysql_fetch_assoc($result))
{  
     ?>
     <body>
     <a href="displayprofile.php" id=<?php =$count1; ?> onclick="validate(this)">
     <?php  print $db_field['fuserid']."<br>";

     ?>
     </a>
     </body>
     <?php
        $count1=$count1+1; 
     }




mysql_close();
?>

according to $db_field the displayprofile.php will chenge but whenever i am trying to use this code i am getting last $db_field variable ??can any one help to solve this problem.

You are badly mixing PHP code in a Javascript function.

then how to solve my problem can you plzz provide me the code

<?php
session_start();
$database="myfriend";
$userid=$_SESSION['user'];
mysql_connect("127.0.0.1","root","");
$db_found=mysql_select_db($database);
$sql="select fuserid from friends where userid='$userid';";
$result=mysql_query($sql);
$id=0;
$users=array();
?>
<body >

<center>
<p> your friends list:</p>

<?php
while($db_field=mysql_fetch_assoc($result))
{  
      ?>

      <a href="displayprofile.php" id='$id' onclick="validate(this)"><?php print $db_field['fuserid']."<br><br>";?></a>
      <?php
          $users[$id]=$db_field['fuserid'];
          $id=$id+1;
 }?>

<head script type="javascript/text">
<script>
function validate()
{
    var id1=document.getElementById(</script><?php print $id ?><script>);
    </script>

<?php
$_SESSION['id'] ?><script >=id1;
}
    </script>    

    <?php
    $id1=$_SESSION['id'];
    $_SESSION['fuserid']=$users[$id1];
    ?>

i used the above code and the o/p is :name1
name2
....
then how can i know which name is selected because depending on the selected name my code changes