Jump to content

Change a jQuery variable with PHP


Hobbyist_PHPer

Recommended Posts

Hi, this is a bit of a PHP and a JQuery question, so I wasn't sure which forum to post it in, but here it is...

 

I need a way to asynchronously change a jQuery variable with PHP when a condition becomes true, without user action.

 

I have the following JQuery:

        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script>
            finished = false;
            
            $(document).ready(function() {
                setTimeout("Refresh()", 5000);
            });
            
            if (!finished) {
                function Refresh() {
                    location.reload();
                };
            }
        </script>

 

Then I have the following PHP code accessing the MySQL database every time the page refreshes... Here's that code:

            <?
            $query = "SELECT * FROM TempAwaitingClients WHERE PSOID = '{$_SESSION['user_id']}'";
            $result = mysql_query($query);
            $rowCounter = mysql_num_rows($result);
            if ($rowCounter > 0)
            {
                while ($row = mysql_fetch_assoc($result))
                {
                    // Condition is true, need to stop the page refreshes
                    echo '<iframe id="audiblealert" name="audiblealert" height="0" width="0" src="telephone-ring-4.wav"></iframe>';
                    echo '<a href="" target="audiblealert">Mute Ringer</a>';
                    echo 'Phone Number: ' . $row['ClientPhoneNumber'] . '<br />
                        Purchased Time: ' . $row['ClientPurchasedMinutes'] . ' minutes<br />';
                }
            }
            else
            {
                echo 'No Clients Yet.';
            }
            ?>

 

Anyone have an suggestions or help?

 

EDIT: I forgot to mention, it's the JQuery variable "finished" that I need to set to TRUE

Link to comment
Share on other sites

finished = <?php echo $somephpvar; ?>;

 

I hope I understood you correctly, here's what I did, it did not work... :

                while ($row = mysql_fetch_assoc($result))
                {
            ?>
            finished = true;
            <?
                    // Condition is true, need to stop the page refreshes
                    echo '<iframe id="audiblealert" name="audiblealert" height="0" width="0" src="telephone-ring-4.wav"></iframe>';
                    echo '<a href="" target="audiblealert">Mute Ringer</a>';
                    echo 'Phone Number: ' . $row['ClientPhoneNumber'] . '<br />
                        Purchased Time: ' . $row['ClientPurchasedMinutes'] . ' minutes<br />';
                }

Link to comment
Share on other sites

Here's the whole page, it's rather small... :

<?
session_start();
include 'includes/connection.inc';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script>
            finished = false;
            
            $(document).ready(function() {
                setTimeout("Refresh()", 5000);
            });
            
            if (!finished) {
                function Refresh() {
                    location.reload();
                };
            }
        </script>
    </head>
    <body>
        <div>
            <?
            $query = "SELECT * FROM TempAwaitingClients WHERE PSOID = '{$_SESSION['user_id']}'";
            $result = mysql_query($query);
            $rowCounter = mysql_num_rows($result);
            if ($rowCounter > 0)
            {
                while ($row = mysql_fetch_assoc($result))
                {
            ?>
            finished = true;
            <?
                    // Condition is true, need to stop the page refreshes
                    echo '<iframe id="audiblealert" name="audiblealert" height="0" width="0" src="telephone-ring-4.wav"></iframe>';
                    echo '<a href="" target="audiblealert">Mute Ringer</a>';
                    echo 'Phone Number: ' . $row['ClientPhoneNumber'] . '<br />
                        Purchased Time: ' . $row['ClientPurchasedMinutes'] . ' minutes<br />';
                }
            }
            else
            {
                echo 'No Clients Yet.';
            }
            ?>
        </div>
    </body>
</html>

Link to comment
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.