Hi all

Is it possible in mySQL to put a timer that changes a value inside a row in a table every while?

For example : Add "1" to the value very 10 minutes for example.. Field number = 5 after ten minutes = 6 after another 10 minuste = 7..Etc..

Is it possible?And how?

Regards..

    I would do this using a php script which is called every 10 minutes by a cron tab.

    or if the page could be open all the time in a browser you could have the following javascript in your body tag to recall the page at the specified interval:

    <body onLoad"setTimeout('document.refresh();', 600000);">
    

    this can also be achieved by using a meta refresh, however I think the javascript should be fine.

      No there is no opened page always.. so there must be something automatically..

      Can this be?

      Regards..

        then the only way that will work is using a cron tab. This is the Unix equivelant to windows task scheduler, some web hosts let you setup tasks called crontabs, you just get it to call the php cgi with the filename, I have never done this myself but others I know have said this is possible.

          Where can I find a tutorial about it?

          My server is RedHat Linux (Apache) so can I use it?

          Regards..

            try looking at
            http://www.4webhelp.net/tutorials/misc/cron.php
            and
            http://forums.devshed.com/archive/5/2002/8/2/39090
            the latter contains two solutions for the crontab, try them and see. One of the examples involves refencing a URL, if you use that and the server is your own then you need to call something like http://127.0.0.1/mytask.php,

            You didn't specify whether the server was your own or hosted, if it is hosted you need SSH access or some kind of control panel that sets up crontabs. If you have neither then this is not possbile at all. You may need to ask your host for this service!

              Thanks for your reply..

              It is a host.. SSH is supported.. so how to do it by SSH (Of course from PHP I mean)

              Regards..

              Notice : I want to update a value in a row for a specified user (Every user has a row)

                I don't know the exact commands for SSH but the cron needs to look something like:

                0 lynx -dump http://www.path/to/my/file.php

                this executes the page every time a new hour starts, to do it every 10 minutes I think you can do:

                0,10,20,30,40,50 lynx -dump http://www.path/to/my/file.php

                if that doesn't work then you will just have to create 6 cron jobs that increment by 10 each time where the 0 is in the example.

                The php should involve a query like:

                UPDATE table_name SET value = $new_value WHERE username = $username;
                

                If you haven't used mysql in php before then I advise having a look at the mysql section of the manual and have a look at the tutorial at webmonkey (both can be found by looking on google).

                  Thank you very much for your help dear..

                  I will read more about the cron and how to link it..

                  Thanks again..

                  Regards..

                    Write a Reply...