npsari Posted June 24, 2007 Share Posted June 24, 2007 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? Quote Link to comment Share on other sites More sharing options...
predator Posted June 24, 2007 Share Posted June 24, 2007 hey npsari order just by date desc and see if this helps. Regards Mark Quote Link to comment Share on other sites More sharing options...
npsari Posted June 24, 2007 Author Share Posted June 24, 2007 It still does the same for some reason, it recognises it from the latest 15 thats strange, any ideas Quote Link to comment Share on other sites More sharing options...
predator Posted June 24, 2007 Share Posted June 24, 2007 is it picking the first 15 records from the database? Quote Link to comment Share on other sites More sharing options...
npsari Posted June 24, 2007 Author Share Posted June 24, 2007 nop, cus iam checking a FriendID from the middle Quote Link to comment Share on other sites More sharing options...
Barand Posted June 24, 2007 Share Posted June 24, 2007 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"; Quote Link to comment Share on other sites More sharing options...
npsari Posted June 24, 2007 Author Share Posted June 24, 2007 Barand, many thanks for the query it worked now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.