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
https://forums.phpfreaks.com/topic/262613-change-a-jquery-variable-with-php/
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 />';
                }

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.