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.

MarthyM
  • 1,839
  • 2
  • 21
  • 23
m4n1c
  • 127
  • 8
  • 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 http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-function-in-php – SDC Nov 13 '12 at 11:23
  • I didn't know that. I m a newbie to php, mysql stuff. Thanks anyways man... – m4n1c Nov 13 '12 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 http://www.phptherightway.com/ - worth a read, although it can be a bit heavy going in places for a complete newbie. – SDC Nov 13 '12 at 11:49

2 Answers2

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.

blue112
  • 52,634
  • 3
  • 45
  • 54
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

Abu Romaïssae
  • 3,841
  • 5
  • 37
  • 59