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? Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/ 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 Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281546 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 Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281549 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? Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281550 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 Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281552 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"; Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281553 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 Link to comment https://forums.phpfreaks.com/topic/56997-solved-a-little-problem-reteiving-data-from-databse-and-using-if-function/#findComment-281562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.