我正在创建一个墙系统,您可以在索引页面上发布更新,我希望帖子只能由用户的朋友看到,我几乎让我的代码工作但我仍然有问题,但在我之前提及我的问题,如果有更好的方法,请与我分享,我会告诉你我的代码
首先我有两个代码表
'my_friends':'id','username','friend'
'雕像':'p_id','post','f_name','userip','date_created'
此代码在post.php中,然后它将包含在索引页面
中 //Check for user's friends
$check = mysql_query("select * from `my_friends` where `username` = '".$username."' order by `id` desc ");
//Get users friends
while($get_users_friends = mysql_fetch_array($check))
{
$show_more_button = 1;
$result = mysql_query("SELECT *,
UNIX_TIMESTAMP() - date_created AS TimeSpent FROM `statues` WHERE `f_name` = '".mysql_real_escape_string(strip_tags($get_users_friends["friend"]))."' ");
}
while($row = mysql_fetch_array($result))
{
$comments = mysql_query("SELECT *,
UNIX_TIMESTAMP() - date_created AS CommentTimeSpent FROM comments where post_id = ".$row['p_id']." order by c_id asc"); ?>
<div class="friends_area" id="record-<?php echo $row['p_id']?>">
<label style="float:left" class="name">
<b><?php echo $row['f_name']; ?></b><br>
<span>
</span><br>
<em><?php echo $row['post'];?></em>
<br clear="all" />
代码无效,它只向一位朋友显示帖子提要,这是用户的第一个添加好友,换句话说,sql $result = mysql_query("SELECT *,
UNIX_TIMESTAMP() - date_created AS TimeSpent FROM
状态WHERE
f_name {{1选择只有一个朋友的所有雕像,当我在sql之前写= '".mysql_real_escape_string(strip_tags($get_users_friends["friend"]))."' ");
它显示所有朋友但是当我在sql中使用它时它没有,请帮助
答案 0 :(得分:0)
以下是一些可能对您有帮助的想法
mysql_*
函数,而是使用PDO
类而不是statues
$result[] =
)SELECT p_id, post, f_name, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM statues WHERE f_name IN '.implode(',', $firends_name)
。您的代码应该类似于:
$check = mysql_query("select friend from `my_friends` where `username` = '".$username."' order by `id` desc ");
while($get_users_friends = mysql_fetch_array($check, MYSQL_ASSOC))
{
$result[] = $get_users_friends['friend'];
}
$friends_data_query = mysql_query("SELECT p_id, f_name, post,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM `statues` WHERE `f_name` IN'".implode(',',$result)."'");
while($friends_data = mysql_fetch_array($friends_data_query,MYSQL_ASSOC)){
但请确保将其重写为PDO。因为现在注射是非常难以理解的。