if/else statements or better

  • Dan030981
  • Novice
  • Novice
  • User avatar
  • Posts: 23
  • Loc: Mass

Post 3+ Months Ago

Hi there,

I hope to get some help with this. I have been playing around with php if/else statements but can't seem to get it right. I don't know if this is the best way to go about this. So if there's a better way please, I'm all ears.

So what I'm trying to accomplish here is. I have this script and inside the script it's a call function. The function display a nice notification box the appear when a user have a new message and disappear in 5 seconds. My problem is it appear everytime when I refresh a page or go to a different page on the site. I would like it to appear ONLY when a user have a new message.

How would I go about using the if/else statements or something similar to that effect so that the notification box only appear when a user receive a new message with the script inside the if/else statement?

Here is the script that I'm using:

Code: [ Select ]
<script type="text/javascript">
  $(function(){
    $.jnotify('Email notification', 'Hi <?php echo $_SESSION['user']->name; ?>, you have <?php echo $num; ?> new messages. Please <a class="inside-links" href="<?php echo $vars['url']; ?>pg/messages/<?php echo $_SESSION['user']->username; ?>" class="privatemessages_new" >click here</a> to view all of your messages' , 'image.png', {lifeTime: 5000});
    });
    </script>
  1. <script type="text/javascript">
  2.   $(function(){
  3.     $.jnotify('Email notification', 'Hi <?php echo $_SESSION['user']->name; ?>, you have <?php echo $num; ?> new messages. Please <a class="inside-links" href="<?php echo $vars['url']; ?>pg/messages/<?php echo $_SESSION['user']->username; ?>" class="privatemessages_new" >click here</a> to view all of your messages' , 'image.png', {lifeTime: 5000});
  4.     });
  5.     </script>
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9102
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Do you have some sort of variable set in PHP that signals if they have a new notification or not? Your first task is to know if they have a new message, I am thinking you have this part already, correct?
  • Dan030981
  • Novice
  • Novice
  • User avatar
  • Posts: 23
  • Loc: Mass

Post 3+ Months Ago

Yes, I have the first part all set.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9102
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

So if you have some variable such as $flag set then you would just do:

PHP Code: [ Select ]
<?php if($flag): ?>
    <script type="text/javascript">
      $(function(){
        $.jnotify('Email notification', 'Hi <?php echo $_SESSION['user']->name; ?>, you have <?php echo $num; ?> new messages. Please <a class="inside-links" href="<?php echo $vars['url']; ?>pg/messages/<?php echo $_SESSION['user']->username; ?>" class="privatemessages_new" >click here</a> to view all of your messages' , 'image.png', {lifeTime: 5000});
        });
        </script>
<?php endif; ?>
  1. <?php if($flag): ?>
  2.     <script type="text/javascript">
  3.       $(function(){
  4.         $.jnotify('Email notification', 'Hi <?php echo $_SESSION['user']->name; ?>, you have <?php echo $num; ?> new messages. Please <a class="inside-links" href="<?php echo $vars['url']; ?>pg/messages/<?php echo $_SESSION['user']->username; ?>" class="privatemessages_new" >click here</a> to view all of your messages' , 'image.png', {lifeTime: 5000});
  5.         });
  6.         </script>
  7. <?php endif; ?>
  • Dan030981
  • Novice
  • Novice
  • User avatar
  • Posts: 23
  • Loc: Mass

Post 3+ Months Ago

Bigwebmaster,

That worked wonderful. Thank you

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 49 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.