Jump to content

[SOLVED] A little problem reteiving data from databse and using if function


npsari

Recommended Posts

I have a table called amigos, which contain thousands of FriendIDs

 

I did this code, which will check if a specific friendID is in the latest 15

 

$qcheck = "SELECT * FROM amigos WHERE FriendID=$FriendID ORDER BY Date DESC, Time DESC LIMIT 0, 15;";

$rescheck = @mysql_query($qcheck,$con);

 

if(mysql_num_rows($rescheck)>0){

print"Your ID is already in the latest 15!";

}else{

print "You ID is not in the latest 15";

}

 

but it always gives the result that is in the latest 15

even if it is far earlier

Why, did i do anything wrong in the query guys?

Link to comment
Share on other sites

You are selecting the last 15 for that friendId.

 

If you want the last 15 records and then see if friend_id is in those, then

$qcheck = "SELECT latest.* FROM
                    (SELECT * FROM amigos ORDER BY Date DESC LIMIT 15) as latest
                WHERE latest.FriendID=$FriendID";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.