Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Last known value of a variable?

    I am using an auto refreshing div to display my users new messages icon as a numeric value. I wanted to play a notification tone when the user receives a new message but I am running into some issues and I am hoping someone can help.


    PHP Code:
    if($inbox_new $_SESSION['inbox'])
      {
      
    $_SESSION['inbox'] = $inbox_new;
      
    $sound 'SET';
      echo 
    “Test”;
      } 
    The problem I am having is that when I try to set $_SESSION['inbox'] = $inbox_new; to indicate the message is no longer new on the next refresh the system acts like there is no new message and ignores anything else I try to tell it to do before the next refresh. $sound will not get “set” and when I echo “Test” it never echo’s. it is like it is making the original ‘if’ statement void.


    I basically need a script that shows two variables.
    $a and $b where $a is from the database and $b is the last known number of the database without calling it.

    I am NOT asking about auto refreshing divs btw…

    I have no idea if I am making any sense here but I have spent the last 12 hours trying to figure a work around on this and am at my wits end. Any help is much appreciated.

  2. #2
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I doubt it helps but here is the last bit of code I was trying to make work...



    PHP Code:
    <?php
    if(!isset($_SESSION['inbox']))
    {
    $_SESSION['inbox'] = '0';
    }
    elseif(
    $inbox_new $_SESSION['inbox'])
    {
    $_SESSION['inbox'] = $inbox_new;
    $sound 'SET';
    }
    elseif(
    $inbox_new != $_SESSION['inbox'])
    {
    $_SESSION['inbox'] = $inbox_new;
    }

    if(isset(
    $sound))
    {
    ?>
    <audio autoplay>
    <source src="./sound/new-mail.mp3" type="audio/mp3">
    <source src="./sound/new-mail.ogg" type="audio/ogg">
    </audio>
    <?php
    }
    ?>

  3. #3
    New to the CF scene
    Join Date
    May 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    everything works just fine if I remove line 8 but then it just constantly triggers the notification and never stops because $inbox_new is always greater then $_SESSION['inbox']...

  4. #4
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    6,424
    Thanks
    30
    Thanked 878 Times in 876 Posts
    When using SESSIONS the FIRST line in the PHP has to be: session_start();
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •