选择特定用户名并在其个人资料中显示

时间:2015-04-29 14:11:29

标签: php mysql

 <?php
    if(!isset($_POST['searchIto'])){
}
       $search_sql="SELECT status FROM users WHERE id=id";
       $search_query=mysql_query($search_sql);

   if(mysql_num_rows($search_query)!=null){

       $search_rs=mysql_fetch_assoc($search_query);
}

 if(mysql_num_rows($search_query)!=null){

  do{?>

   <span>Status:&nbsp;</span><?php echo $search_rs['status'];?><br>

<?php

     }while($search_rs=mysql_fetch_assoc($search_query));
}

else{
    echo "No results found";
}
?>

此代码回显所有已注册的状态,我只想显示已登录的特定用户的状态。例如,如果user1的状态值为1 display 1且user2的状态值为2 display 2

1 个答案:

答案 0 :(得分:0)

经过几次调试,我找到了解决方案:

 <?php

$startNa = $_SESSION['user_id'];
$search_sql="SELECT status FROM users WHERE id='$startNa'";
$search_query=mysql_query($search_sql);

  if(mysql_num_rows($search_query)!=null){
   $search_rs=mysql_fetch_assoc($search_query);
}
  if(mysql_num_rows($search_query)!=null){
     do{?>
<span>Status:&nbsp;</span><?php echo $search_rs['status'];?><br>

<?php
       }while($search_rs=mysql_fetch_assoc($search_query));
}
else{

echo "No results found";
}
?>

我只是添加$ _SESSION []; 顺便说一句,谢谢你的回答,你帮助了我很多。