colleyboy Posted June 29, 2012 Share Posted June 29, 2012 I have an if statement: // if they are logged in $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$loggedinuserid"); while($row = mysql_fetch_array($aretheyliked)) { if (($row['liked_user_id']==$profileuserid)&&($row['user_id']==$loggedinuserid)){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } else { echo "<FONT SIZE=2 COLOR=BLUE>Like"; } The idea is if the user is logged in they can click the "like". If they already like it it will say they already do like it. The else is not showing though. What am I doing wrong... it works when it matches but not when it dont Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/ Share on other sites More sharing options...
scootstah Posted June 29, 2012 Share Posted June 29, 2012 I don't see anything syntactically wrong. Is it showing up in the page source? Maybe you have malformed HTML somewhere (speaking of which, you need to close those two font tags (actually you should really be using CSS instead of font tags, but I digress)). Also, this &&($row['user_id']==$loggedinuserid) is unnecessary since you are only selecting rows with that user id to start with. Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358015 Share on other sites More sharing options...
colleyboy Posted June 29, 2012 Author Share Posted June 29, 2012 Hello, I have gave you an extended snippet of the code and removed the && as I see I reference it twice (good spot ). The <FONT> tags are temp until I sort the code then I will cleanup with some CSS . <!-- LIKE BUTTON --> <?php if (isset($_SESSION['useridkey'])){ //check user id in url matches useridkey if ($_SESSION['useridkey']==$the_user_id){ // the following if the session id matches the variable //edit profile page echo "sessionid matches the user id variable"; } $loggedinuserid = $_SESSION['useridkey']; // if they are logged in $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$loggedinuserid"); while($row = mysql_fetch_array($aretheyliked)) { //if they are liked by the user if (($row['liked_user_id']==$profileuserid))){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } else { echo "Like"; } } // end of if they are logged in } else { // if they are not logged in echo "<FONT SIZE=1 COLOR=RED>You must be logged in to like this artist"; } ?> <!-- END OF LIKE BUTTON --> Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358019 Share on other sites More sharing options...
colleyboy Posted June 29, 2012 Author Share Posted June 29, 2012 Tried an elseif statement too (!=) but still isnt showing the echo... hmm Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358025 Share on other sites More sharing options...
Pikachu2000 Posted June 29, 2012 Share Posted June 29, 2012 Is it showing up in the page source? Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358026 Share on other sites More sharing options...
colleyboy Posted June 29, 2012 Author Share Posted June 29, 2012 No it is blank on the page source where it should say "like" Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358029 Share on other sites More sharing options...
Pikachu2000 Posted June 30, 2012 Share Posted June 30, 2012 Are you sure the last code you posted is the code you're actually running? That code throws a fatal parse error when I run it. EDIT: And do you have error reporting set up to display all errors? Quote Link to comment https://forums.phpfreaks.com/topic/265012-not-showing-the-else-info/#findComment-1358050 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.