Completed

MySQL query to display 10 of user's friends sorted by most recently corresponded with friends

I created a small chat box on my website that shows 10 thumbnails for a quick way to open a chat window to communicate with the user's friends. The user may have 1000 friends or more, so the 10 thumbnails should be of most recently communicated with friends. Currently I'm just using a simple query displaying 10 of the user's friends sorted by user's friend's last_activity, which is a timestamp. This can become a problem as the site grows and the user has many friends online, the thumbnails will rearrange every few seconds.

<?php

$sel = "SELECT friends.user_id, friends.friend_id, [login to view URL], users.user_id, [login to view URL], users.last_activity FROM friends, users WHERE friends.user_id = ".$_SESSION['user_id']." AND users.user_id = friends.friend_id AND [login to view URL] = 2 ORDER BY last_activity DESC LIMIT 12";

$recent_friends = mysqli_query($link,$sel);

while($my_friends = mysqli_fetch_array($recent_friends))

{

$online_status_msg = "OFFLINE";

$online_status_class = "disconnected";

$onlineStyle="background-color: #ff4f60;";

if(time() - $my_friends['last_activity'] <120) {

$online_status_class = "online";

$onlineStyle="background-color: #32e4cd;";

}

elseif(time() - $my_friends['last_activity'] <300) {

$online_status_class = "away";

$onlineStyle="background-color: #ffd52f;";

}

$checkMsgs = mysqli_fetch_array(mysqli_query($link,"SELECT id FROM inbox WHERE user_id = ".$_SESSION['user_id']." AND `author` = ".$my_friends['user_id']." AND `read` = 0 LIMIT 1"));

$newMsg="";

if($checkMsgs['id']>0){

$newMsg="newMsg";

}?>

<li class="inline-items js-chat-open" data-id="<?=$my_friends['user_id']?>">

<div class="author-thumb">

<img alt="author" src="<?=justGetThumbSource($my_friends['user_id'])?>" class="avatar <?=$newMsg?>" style="max-width:34px;">

<span class="icon-status <?=$online_status_class?>" style="<?=$onlineStyle?>"></span>

</div>

</li>

<? } ?>

The `outbox`

Skills: PHP, MySQL, Software Architecture

See more: edit csv mysql query, asp mysql query, 2013 lost connection mysql query, mysql query report, php mysql query table, mysql query record bash, mysql query csv file, write mysql query, display mysql query ajax menu, display mysql query php table easy, mysql query display results csv file, display mysql query joomla website, display results mysql query, send email display dear user mysql php, iphone app display mysql query, mysql query display php, page display name user mysql, smarty display mysql query, Featured Snippet Writing for Health and Nutrition- Summary of an answer to a user\ s query- 100 questions

About the Employer:
( 1 review ) Bethel, United States

Project ID: #21183599

Awarded to:

bjrupani

Hello hiring member i hope you are doing well i am bhavika i have 4+years experience in php , laravel ,ajax , jquery , javascript , html ,css , bootstrap i have done many things with php , mysql and i can do it and i c More

$25 USD in 1 day
(138 Reviews)
6.6

35 freelancers are bidding on average $31 for this job

yuriyes43

This is Pavel who is on discussing with you via chatting. Please drop me a message for further discussion. Thanks.

$20 USD in 1 day
(90 Reviews)
6.9
jamesmartin81

I have experience of Website in PHP, Laravel, CodeIgnitor, Wordpress, Opencart, Woocommerce, Photoshop, Adobe Illustrator . We also have experience of making Android,Window and iphone application with ionic & phonegap. More

$20 USD in 1 day
(128 Reviews)
6.0
nisharapath

Dear employer! Thanks your your job posting. I read your project and I am interested in this field. As you can see my profile, I have rich experiences in PHP and MySQL. If you hire me, I will do my best and you will se More

$30 USD in 1 day
(33 Reviews)
5.9
mohamedgb00714

Hello, I can help you with this just contact me and let's start the work immediately :)

$20 USD in 7 days
(95 Reviews)
6.1
NishchayTech

CAN COMPLETE WITHIN 1 HOUR. I am a PHP and MySQL expert and have built LOTS of similar systems to yours. I have 5+ years experience with PHP and MySQL. Message me NOW and I can start now.

$50 USD in 1 day
(57 Reviews)
5.7
appbank888

Hello, Nice to meet you. I have over 5 years of Exp around the web. I have checked your project descriptions and think I can help you. If you want to hire me, we can make a good result quickly i think. Please feel fre More

$30 USD in 1 day
(24 Reviews)
6.1
hengzhulu

Hi, I have read carefully to your proposal and I can help you. As a best DBA, I have rich experience with DB migration, System Speed Tuning, Database Optimization, Big-Data Manipulation and so on. I would like discu More

$50 USD in 1 day
(13 Reviews)
5.5
DianaBorisov

Hi, Got your project requirements here. Thanks for your sharing it. I have been doing back-end and front-end developer with more than 8 years My main skill: PHP(Laravel, Codegniter, Yii, Wordpress), NodeJs, JSP, JQu More

$20 USD in 7 days
(34 Reviews)
5.7
BorisMonday2018

Hi, sir. I have read this project very carefully. I am a senior web developer. I have developed a lot of web and mobile apps for 6 years. I have rich experience with Graphic Design, PHP, MYSQL, HTML, CSS, JAVASCRIPT, j More

$20 USD in 7 days
(53 Reviews)
6.0
webcodeater

i can solve this right now,i can solve this right now,i can solve this right now,i can solve this right now,i can solve this right now,i can solve this right now

$25 USD in 1 day
(80 Reviews)
5.7
TopDesigner315

Hello :) Thanks for your job posting. I saw your description carefully. I am a Senior web Developer who have 8+ years of experiences. My skills are Html5,CSS,SCSS, Bootstrap,Javascript,Jquery,MySql,PHP especially QUER More

$50 USD in 1 day
(27 Reviews)
5.1
freelancerdanie9

Hi, I have just read your requirements carefully. As professional web developer has over 8 years of experience in development. I have rich experience with Laravel, CodeIgniter, Wordpress and Angular.js,React.js,Vue.js More

$30 USD in 7 days
(7 Reviews)
5.1
AlexanderPGR

HI, there. I am interested in your task. I have high PHP and Mysql skill and can work anytime. Please contact me and discuss, Thanks.

$20 USD in 1 day
(26 Reviews)
5.1
snowman718718

Hi. Here is a skillful full stack web developer. Thank you for your posting. I have 4+ years of experience in projects like yours. Once you choose me, I'll deliver the perfect result Thanks in advance.

$35 USD in 1 day
(19 Reviews)
5.1
aykutcanturkmen

Dear, client. As you can see my review I'm expert at Javascript and ReactJS and Angular and PHP... Of course Laravel and Codeignitor is perfect. The person who experts at Javascript can clearly finish all web project. More

$50 USD in 1 day
(29 Reviews)
5.1
romansokolv708

Hi, I'm very glad to bid your project. I've read your job post carefully. This job really attracts me and also your required skills are completely matched with my major skills. I have good knowledge and rich experienc More

$50 USD in 1 day
(16 Reviews)
4.8
sharktiger

Hi, dear! I am glad to bid your project. I have many experiences in website design and development. My rich development experience will give you amazing result for your project. I am serious bidder, so I only bid on pr More

$20 USD in 1 day
(20 Reviews)
4.7
stepan2019

Hello How are you? Thank you sharing for your post project I am very interesting for your post project. If you want to same other friend information show on your website, i can help you. I think you have got already fo More

$20 USD in 7 days
(10 Reviews)
4.5
BestService222

⭐ Dear Client. ⭐ I have just read your requirements carefully. I am very interested in your project. Although I am new in freelancer, I have more than 5 years of experiences in Database Administration. I'm an expert in More

$30 USD in 2 days
(24 Reviews)
5.1
liujianmin

Hello, Client. Nice to meet you. I saw your job description carefully and understood what you want I am so interested in your project and want to work with you, I am senior web developer with rich experience of SQL q More

$17 USD in 1 day
(23 Reviews)
4.1