monkeybidz Posted September 19, 2007 Share Posted September 19, 2007 Im trying to check if a user exist in database table only if another check =YES: $sql="SELECT * FROM my_members WHERE my_private=$my_private AND my_id=$my_id"; $my_private should = 'Yes' or 'No'. If 'Yes', i need to run another check.... $sql="SELECT * FROM my_favorites WHERE my_id=$my_id AND my_uid=$sessionuser"; This check should check to see if $sessionuser exists in my_favorites.. How can i make the first one call the second only if $my_private=Yes? Or is this code even correct? Quote Link to comment https://forums.phpfreaks.com/topic/69846-check-mysql-database-for-user/ Share on other sites More sharing options...
Psycho Posted September 19, 2007 Share Posted September 19, 2007 How about 1 query instead? $sql=" SELECT mf.* FROM my_favorites mf RIGHT JOIN my_members mm ON mf.my_id = mm.my_id WHERE mf.my_id=$my_id AND mf.my_uid=$sessionuser mm.my_private=$my_private"; Quote Link to comment https://forums.phpfreaks.com/topic/69846-check-mysql-database-for-user/#findComment-350878 Share on other sites More sharing options...
ShoeLace1291 Posted September 19, 2007 Share Posted September 19, 2007 $sql="SELECT * FROM my_favorites WHERE my_id=$my_id AND my_uid=$sessionuser"; $num = mysql_num_rows($sql); if($num > 0){ do some action } Quote Link to comment https://forums.phpfreaks.com/topic/69846-check-mysql-database-for-user/#findComment-350879 Share on other sites More sharing options...
monkeybidz Posted September 19, 2007 Author Share Posted September 19, 2007 Both did not work for me in that page, but did work in others. What i cant get it to recognize both variables at the same time. If($my_private=='Yes' && !$sessionuser) { header("Location: gen_confirm.php?errmsg=".urlencode("This user has profile set to private. Only friends can view this page.<BR><a href=".addme_request.php.">Click here to request to be added.</a>")); die(); } I can get it to check the my_private, but not the my_ud from database. ??? Quote Link to comment https://forums.phpfreaks.com/topic/69846-check-mysql-database-for-user/#findComment-350886 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.