A little problem reteiving data from databse and using if fu
Question:
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?
Answers:
hi,
Logically your query is wrong.
U can try somethin like:
I hope you will have a primary key field called ID
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?
Answers:
hi,
Logically your query is wrong.
U can try somethin like:
| Code: |
| SELECT * FROM amigos WHERE FriendID=$FriendID AND ID IN ( SELECT ID FROM amigos ORDER BY Date DESC, Time DESC LIMIT 0, 15) |
I hope you will have a primary key field called ID
Commentaires
Enregistrer un commentaire