is it posible to increase a mysql table default value to increase by a number based on another number
E.X.

i have a default value set to 10 how do i increase it by 1 every 3 minult
also if i add a new number "3"(in a box or text fild) in stated of adding to the default value (10) 1 add 3 every 3 minuts

Member Avatar for diafol

Could you give more info about what you're trying to do. I can't really grasp the concept.

If you've set an increment in a form, you can then start a javascript interval based on that, increasing the base number every 3 minutes. The form submission can then send a value (javascript-altered).

This could be an ajax solution - but avoid if possible - too much overhead.

Alternatively php can do a starttime when the form is originally sent (set in a hidden form value) along with another hidden field holding the increment value, in your second page. The total can then be calculated at the time that the second form is sent.


second form handler:

$default_value = "10"; //set manually or get value from db
$endtime = date('U'); //set "now" in seconds from UNIX epoch
$starttime = $_POST['starttime']; //from hidden value in second form which was set just as endtime.
$increment_value = $_POST['increment']; //from hidden value in second form

$timeperiod = $endtime - $starttime; //elapsed time in seconds
$increment_periods = ceil($timeperiod/180); //number of 3 minute periods in timeperiod. Rounded up in this eg. OR you could round down with floor()

$new_value = $default_no + ($increment_periods * $increment_value);

use $new_value in your SQL query.

Member Avatar for diafol

Sorry just read back my first response - a little cryptic. The following code off top of my head, so not tested:

form1.php

<form id="setvals" name="setvals" method = "post" action ="form2.php">
    <label for="interval">Interval (mins):</label>
    <input id="interval" name="interval" type = "text" />
    <label for="increment">Increment:</label>
    <input id="increment" name="increment" type = "text" />
    <input type="submit" id="sendvals" name="sendvals" value="Send Values" />
</form>

form2.php

<?php
$starttime = date("U");
if(isset($_POST['increment']) && isset($_POST['interval']) && is_int($_POST['increment']) && is_int($_POST['interval'])){ 
?>
<form id="stoptime" name="stoptime" method="post" action="handler.php">
    <input id="interval" name="interval" type = "hidden" value="<?php echo $_POST['interval'];?>" />
    <input id="increment" name="increment" type = "hidden" value="<?php echo $_POST['increment'];?>" />
    <input id="starttime" name="starttime" type = "hidden" value="<?php echo $starttime;?>" />    
    <input type="submit" id="sendstop" name="sendstop" value="Stop Time" />
</form>
<?php
}else{
    echo "<p>Bad data! ...(include link back to form1.php)...</p>";
}
?>

handler.php

<?php
$default_value = "10"; //set manually or get value from db
$endtime = date('U'); //set "now" in seconds from UNIX epoch
$starttime = $_POST['starttime']; //from hidden value in second form which was set just as endtime.
$increment_value = $_POST['increment']; //from hidden value in second form
$interval_value = $_POST['interval'];//ADDED 
$timeperiod = $endtime - $starttime; //elapsed time in seconds
$no_intervals = ceil($timeperiod/$interval_value); //Rounded up in this eg. OR you could round down with floor()
 
$new_value = $default_no + ($no_intervals * $increment_value);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.