显示用户标识的名称

时间:2014-04-14 16:20:20

标签: php mysql sql project social

我使用一个用户的ID和另一个用户的ID设置了friends的表格,我正在尝试获取登录用户的ID并搜索与其friends配对的每个其他用户的ID然后获取其ID并将其与名为s_users的表中的ID匹配,然后显示这些用户的名称在特定于用户登录的表中。有任何帮助吗?

这是显示谁登录并获取其ID(工作)的代码。

<?  
require("includes/db.php");
session_start();
$member_id = $_SESSION['member_id'];

//Employee Login database   
$result = mysql_query("SELECT * FROM s_user WHERE ID='$member_id'") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$name = $row['user_nicename'];
echo "'$name'";
?>

这是我显示所需信息的代码,我不知道我从哪里开始:

<?php 
$query = 'select * from s_user as A inner join s_friends as B on A.ID = B.user_id';
$statusresult = mysql_query($query);
while($row = mysql_fetch_array($statusresult))
{
  $postdate = strtotime($row['status_time']);
  echo '<table cellpadding="2" cellspacing="0" border="1" width="100%">
        <fieldset>
            <legend>
          '.$row['user_nicename'].'
            </legend></td>
            <hr>
    </table>
        </fieldset>
    <hr />';
} 
?>

3 个答案:

答案 0 :(得分:0)

Select * from s_user as A inner join s_friends as B on A.ID = B.user_id AND A.id = $_SESSIOn['memberid'];

请确保您使用mysql注入的预防策略并将查询升级到mysqli

答案 1 :(得分:0)

嗯,没有任何错误消息很难处理......

首先,您的SQL已关闭。 你有 $ query ='select * from s_user as a inner join s_friends as B on A.ID = B.user_id'; 但是不要传递要为其转发朋友的用户的实际ID。 你了解加入的概念吗? (我要求不要抨击你,但要弄清楚从哪里开始)

答案 2 :(得分:0)

好的尝试过,它运行正常:

<?php 
$member_id = $_SESSION['member_id'];
$query = 'select A.* from s_user as A inner join s_friends as B on A.ID = B.user_id where friend_id='.$member_id;
$statusresult = mysql_query($query);
while($row = mysql_fetch_array($statusresult))
{
  $postdate = strtotime($row['status_time']);
  echo '<table cellpadding="2" cellspacing="0" border="1" width="100%">
        <fieldset>
            <legend>
          '.$row['user_nicename'].'
            </legend></td>
            <hr>
    </table>
        </fieldset>
    <hr />';
} 
?>