Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/
Share on other sites

<?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 :)

Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428343
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428346
Share on other sites

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 by Strider64
Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428354
Share on other sites

 

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.

Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428357
Share on other sites

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!"
}
?>
Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428371
Share on other sites

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 by lanox
Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428380
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/277651-if-statemen-in-php/#findComment-1428399
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.