PHP_USER1
PHP_USER1

Reputation: 628

task scheduler after 5 min

<?php
    mysql_connect("localhost", "root", "");
    $db=mysql_select_db("test");
    $i=1;
    $r=" INSERT INTO test1 (score) VALUES ('$i') "  ;
    $t=mysql_query($r);
    if($t)
    {
    $d="select score from test1";
    $x=mysql_query($d);
$count=mysql_num_rows($x);
if($count>0)
{ 
while($row=mysql_fetch_array($x))
{

   $i=$row['score']+5;

    echo $i;
    echo "<br>";
    }}}

In this I am just inserting the $i value into the database ie 1 , after that by using select i capture the last value and add 5 in it but it is not working and i cant use the session also because i am working on task scheduler , it means after 5 mins my script will run and update the database but in my database it just showing 1 only

Upvotes: 1

Views: 122

Answers (2)

codeGig
codeGig

Reputation: 1064

<?php
mysql_connect("localhost", "root", "");
$db=mysql_select_db("test");
$i=1;


$d="select score from test1 order by id desc limit 1 ";
$x=mysql_query($d);
$count=mysql_num_rows($x);
if($count>0) { 
   $row=mysql_fetch_array($x))
   $i=$row['score']+5;
}

$r=" INSERT INTO test1 (score) VALUES ('$i') "  ;
$t=mysql_query($r);
?>

Upvotes: 0

Rab
Rab

Reputation: 35582

The Insert Should be Performed after select, then you will be able to insert the updated value.

Currently you are getting the value from database add 5 to it and then leave. and insert has already been done for 1 in the start of the script

Upvotes: 1

Related Questions