0

I have a file which is of php type. And I have a combination of HTML elements, javascript functions and some PHP scripts as well. I want to rerun the php script say some part of the script again and again. lets take this example:

<html>
    <?php
        $connection = mysql_connect('localhost','root','root');
        $db = mysql_select_db('messenger');
        if ($db == null)
        {
            echo "hello";
        }

        $messagecheck = "select * from Messages where destination = '$user' && status = 'ACTIVE'";
        $result = mysql_query($messagecheck);
        $no_rows = mysql_num_rows($result);
        ............
    ?>
    <body>
        ........
        <form>
            <input type="submit">
            .......
        </form>
    </body>
</html>

I want to run the above php script continuously for every 1 min from the same file. When I make use of location.reload() I find that complete document gets reloaded. I just want the affect the part of the page which php script accesses and not the whole doc.

How can I do that? Please help.

3
  • 2
    off-topic, but please be aware that the mysql_xx() functions are considered obsolete and are being deprecated. It is recommended to switch to the mysqli_xx() functions or the PDO library, both of which are more secure, more up-to-date, and have more functionality. See also stackoverflow.com/questions/12859942/… Commented Nov 13, 2012 at 11:23
  • I didn't know that. I m a newbie to php, mysql stuff. Thanks anyways man... Commented Nov 13, 2012 at 11:27
  • no worries; I guess it's good to find out now when you're just getting started rather than later when you've got a whole stack of code already written. The old mysql_xx() funcs have been around forever, so there are a ton of old tutorials that use them which haven't been updated. But it's good to learn from tutorials that teach current best-practices. You might like to see phptherightway.com - worth a read, although it can be a bit heavy going in places for a complete newbie. Commented Nov 13, 2012 at 11:49

2 Answers 2

4

You can't do that out of the box, since php is called when the page is loaded.

You should take a look at Ajax or frameworks like JQuery, that embed Ajax.

Sign up to request clarification or add additional context in comments.

Comments

1

As previously said by blue112 you need to use Ajax in order to get what you want.

If I did understand well what you need, a simple solution is using an iframe where you point to a file with only the php code you want to execute, and reload it every time you want.

I hope this helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.