lanox Posted May 5, 2013 Share Posted May 5, 2013 Hi Guys been borwsing and learning from here and i though it was time to register. I was wondering if someone could help me with if statment that i am stuck here is my if statment <?php if ({total_unread_private_messages} != 0): ?> {total_unread_private_messages} <?php endif; ?> Now to explain {total_unread_private_messages} --> this is variable to show number of how many messages you have by default it always shows 0 till u dont get a private message then it increases to 1 and so on. now what i am trying to achive is this. if count is 0 dont display anything, if you receive message then i wan to display 1 unread message. which what my if statmen does but this is where it failes. if you read the private message counter will reset to 0 but it will not desaper it will say 0 unread messages. i am not sure what i am doing wrong ? ( i assuming its not checking if the count is 0 then dont display anything ? if someone could help would be much appreaciated. thanks in advance. Quote Link to comment Share on other sites More sharing options...
Phear46 Posted May 5, 2013 Share Posted May 5, 2013 <?php if ($total_unread_private_messages != 0) { echo "You have $total_unread_private_messages unread messages"; } ?> Where have you been learning php? Ive not seen variables defined with { } braces before but Im also new to this resetting the counter is a bit more advanced, start with the basics Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 Hi Tnx for reply It's not variable as such it's like a link where the code is stored and that calls the code and displays number of new messages. And it resets it self once the member clicks on the new message and reads it. My issue is that my code doesn't check if the count is 0 I am assuming. Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 anyone ? Quote Link to comment Share on other sites More sharing options...
Strider64 Posted May 5, 2013 Share Posted May 5, 2013 (edited) How's this? (Didn't see the part where you want it click, but I'm tired this morning. Maybe you can figure it out on your own or someone else can help you?) <?php $total_unread_private_messages = 14; if ($total_unread_private_messages) { echo "The Detroit Tigers are No. 1 and you have " , $total_unread_private_messages; } else { echo 'The Detroit Tigers are not playing today and you have ', $total_unread_private_messages; } echo '<br>'; $total_unread_private_messages = 0; if ($total_unread_private_messages) { echo "The Detroit Tigers are No. 1 and you have " , $total_unread_private_messages; } else { echo 'The Detroit Tigers are not playing today and you have ', $total_unread_private_messages; } Edited May 5, 2013 by Strider64 Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 right tnx. Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 How's this? (Didn't see the part where you want it click, but I'm tired this morning. Maybe you can figure it out on your own or someone else can help you?) <?php $total_unread_private_messages = 14; if ($total_unread_private_messages) { echo "The Detroit Tigers are No. 1 and you have " , $total_unread_private_messages; } else { echo 'The Detroit Tigers are not playing today and you have ', $total_unread_private_messages; } echo '<br>'; $total_unread_private_messages = 0; if ($total_unread_private_messages) { echo "The Detroit Tigers are No. 1 and you have " , $total_unread_private_messages; } else { echo 'The Detroit Tigers are not playing today and you have ', $total_unread_private_messages; } Strider, That is fine, i have tried to figure it out my self but unfortunately i haven't as of yet. Basically the total_unread_private_messages does all the work including incrementing the numbers and resetting back to 0, what i cant figure out is how to hide 0 when there is no new messages. Quote Link to comment Share on other sites More sharing options...
Phear46 Posted May 5, 2013 Share Posted May 5, 2013 is total_unread_private_messages a function? what does it return? what do you mean hide 0 when there are no messages? You only want a message displayed when there ARE new messages? otherwise display nothing? <?php if ($total_unread_private_messages == 0) { //Do nothing } else { echo "You have $total_unread_private_messages new messages!" } ?> Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 (edited) Hi Phear thank you for helping this is the function that i have wrote in mod.forum.php ( file) ** * Unread Private Message Box in header */ public function unread_private_messages() { $str = $this->load_element('unread_private_messages'); $pms = $this->EE->session->userdata('private_messages'); if ($pms == '' OR ! is_numeric($pms)) { $pms = 0; } if ($pms > 0) { $str = $this->allow_if('private_messages', $str); $str = $this->deny_if('no_private_messages', $str); } else { $str = $this->deny_if('private_messages', $str); $str = $this->allow_if('no_private_messages', $str); } return $this->var_swap($str, array( 'total_unread_private_messages' => $pms ) ); } what i mean by nod showing 0 in my forum the function above will display number of new private message if there is no new private message it show number 0 what i would like is to hide that 0 so it doesn show. This is what my member currently ses when they login user name: bob | 0 UNREAD MESSAGES what i would like for them to see if there is no new messages user name: bob and this is what i would like to see if there is a message user name: bob | 1 UNREAD MESSAGE once they read message i would like it to go back to user name: bob at the moment its actually showing user name: bob | 0 UNREAD MESSAGES after they read they message i want to hide that 0 UNREAD MESSAGES. thanks heaps Edited May 5, 2013 by lanox Quote Link to comment Share on other sites More sharing options...
Phear46 Posted May 5, 2013 Share Posted May 5, 2013 ok, can you show me the code on your page that displays 'user name: bob | 0 UNREAD MESSAGES' and can you show me the output of: echo unread_private_messages(); Quote Link to comment Share on other sites More sharing options...
lanox Posted May 5, 2013 Author Share Posted May 5, 2013 It's currently running on my server not facing Internet I can try uploading or if u want a screen shoot Echo of that displays 0 Quote Link to comment Share on other sites More sharing options...
Phear46 Posted May 5, 2013 Share Posted May 5, 2013 ok, so you dont need to change your function. you need to edit your page dispaying the 'user: bob | 0 unread messages' im guessing the code you currently have says something like echo "user: $username | unread_private_messages() unread messages"; change it to something like: if (unread_private_messages() > 0) { echo "User: $username | " . unread_private_messages() . " Unread messages"; } else { echo "User: $username"; } If thats not what your after i have no idea what you mean, sorry! Maybe someone more knowledgeable than me can offer a better suggestion. Quote Link to comment Share on other sites More sharing options...
lanox Posted May 6, 2013 Author Share Posted May 6, 2013 jsut an update, i got it sorted using my original code in first post, the issue was that i didn't enable php in my expressionengine , as soon as i did that all worked as expected. Quote Link to comment 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.