I am working on a project where I need to maintain user specific content.
One user can view one content only one time in 24 hours.
After 24 hours it will be made available to the same user again.
So when a user successfully views a content I store the username of the user in the database in a comma separated value.
For example: when the user user1
successfully views a content his username will stored in user_status
as user1
along with other users likes user1,user2,user3,.......,etc
.
Now what I want is to check the content if the username user1
exists in the database or not.
If it exists then content will not be made available to him for next 24 hours.
But for some reasons I cannot check a particular user from the group of comma separated usernames using if...else
.
I can do it with if...else
and explode but that does not satisfies my need. I want to know that can I check for one username in the WHERE clause of SELECT statement?
For ex. something like SELECT * FROM user_data WHERE user_status != '".$something."'
.
Is it possible by using explode first then checking it in WHERE clause or just by some other method? If yes, then how? Please help me php experts.
Is it possible something like this?
$uname = $_SESSION['username'];//username of the logged in user
$ths = "SELECT * FROM user_data";
$its = mysql_query($ths) or die(mysql_error());
$uhs = mysql_fetch_array($its);
$user_status = explode(',', $uhs['user_status']);// first explode the comma separated usernames
$ths = "SELECT * FROM user_data WHERE user_status != '".$uname."'";// then check if the logged in username does not exists in the database
$its = mysql_query($ths) or die(mysql_error());
Can the exploded list of usernames be checked in the WHERE clause? Is it possible? Or is there any method to do this? If yes then how?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…