首页 / PHP / php – Mysql朋友在线显示
php – Mysql朋友在线显示
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Mysql朋友在线显示,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1878字,纯文字阅读大概需要3分钟。
内容图文
好的,所以我从搜索无处不在如何解决这个问题.我试图向在线用户展示,但不是所有用户,只有谁在你的朋友列表中…
所以我有一个名为users_online的表,当用户登录我的网站时,该表会自动创建1行,包含date,ip,name,user_id和friend_array(保存所有用户的朋友)
例如,我登录我的网站,并在users_online表中创建行.我想只在网上看到我的朋友,这些朋友都存储在friend_array栏目中(1,5,16,5(那是朋友的身份证号码))..我如何从friends_array列中获取数据并查看这些id中的哪一个被记录目前,这意味着哪些id存在于user_online表中并显示在我的个人资料中?
我希望不要混淆问题……
那就是我的代码..所有商店都在online.php文件中:
// Checking wheter the visitor is already marked as being online:
$inDB = mysql_query("SELECT user_id FROM users_online WHERE user_id=".$userid);
if(!mysql_num_rows($inDB))
{
// Selects some data required to insert into users_online table from users table
$DB = mysql_query("SELECT img,fname,friend_array FROM users WHERE user_id=".$userid);
while($row=mysql_fetch_assoc($DB))
{
$img = $row['img'];
$fname = $row['fname'];
$farray = $row['friend_array'];
}
mysql_query(" INSERT INTO users_online (user_id,ip,img,fname,friend_array)
VALUES(".$userid.",'".$intIp."','".$img."','".$fname."','".$farray."')");
}
else
{
// If the visitor is already online, just update the dt value of the row:
mysql_query("UPDATE users_online SET dt=NOW() WHERE user_id=".$userid);
}
// Counting all the online visitors:
// Thats where i need to work out with friend array..
// I need to display all online friends only
list($totalOnline) = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users_online"));
// Outputting the number as plain text:
echo $totalOnline;
解决方法:
<?php
$friends = array(1,5,16); // Array of friends
$friendIDs = implode(',', $friends); // Turns array into string for SQL select statement
// Gets only friends info from DB
$sql = "
SELECT date, ip, name, user_id
FROM users_online
WHERE user_id IN (".$friendIDs.")";
?>
内容总结
以上是互联网集市为您收集整理的php – Mysql朋友在线显示全部内容,希望文章能够帮你解决php – Mysql朋友在线显示所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。