Hi, I'm creating a website where users can liket things and by liking things you'll see people who have liked the same thing on your home page. Now, currently my code shows people who like ONE same thing as you, but how would I make it so that if anyone has multiple things that they like that you also like, they'll show up first? So basically it will rank the people based on how many things they like that you like.

<?php

$liked_query = mysqli_query ($link, "SELECT whats_liked FROM whatilike WHERE user_liked_by='$user' ORDER BY id ASC LIMIT 10");

$num_rows_liked = mysqli_num_rows ($liked_query);
if ($num_rows_liked !=0) {
while ($fetch_row = mysqli_fetch_assoc ($liked_query)) {
$thing_liked = $fetch_row ['whats_liked'];
$people_like = mysqli_query ($link, "SELECT user_liked_by FROM whatilike WHERE whats_liked LIKE '%$thing_liked%' && user_liked_by !='$user'");
while ($rpl = mysqli_fetch_assoc ($people_like)) {
$person_like_u = $rpl ['user_liked_by'];
$pluq = mysqli_query ($link, "SELECT profile_pic FROM users WHERE username='$person_like_u'");
while ($pluqr = mysqli_fetch_assoc ($pluq)) {
$pli = $pluqr ['profile_pic'];
echo "<a href='profile.php?u=$person_like_u'><img src='data/user_photos/$pli' height='50px' width='50px'
 style='border-radius:400px;'></a>";
 ?>

Btw I deleted all the styling from this code to make it easier for you all to read.

Although not directly an answer, this code snippet shows how it can be done for tagging, which is basically the same.

You might want to show your tables, some data and expected result, so we can see what you are working with.

Okay, thanks! Table : whats_liked, date_liked, user_liked_by
If user types I like DANIWEB, daniweb will be inserted into whats_liked, the user_liked_by will be the logged in user. Lets say the user types I like potatoes, I like, Daniweb, I like computers. If another person types in I like computers. I like Daniweb. Then that person will be showed above all the other users because he has more likes in common with person.

i checked out the link, but its a bit confusing. could u help me apply the code to my scenario?

Show some sample data (records from your table).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.