Update one column of data in the table
玛莎拉蒂
玛莎拉蒂 2017-08-19 10:24:47
0
3
1419

Table table1

id user_name numbers wtime

1 Jack 12 2017-08-19 10:08:28

3 Andy 34 2017-08- 19 10:08:37

4 Lulu 24 2017-08-19 10:09:04

I want to update the numbers column in table1 according to the formula; for example, the numbers column is multiplied by 0.01.

The following table should be drawn:

id user_name numbers wtime

1 Jack 12.12 2017-08-19 10:08:28

3 Andy 34.34 2017-08-19 10:08:37

4 Lulu 24.24 2017-08-19 10:09:04

I have been writing for a long time and I can’t figure out a way. Please help me.

玛莎拉蒂
玛莎拉蒂

reply all(3)
[鸡]彬彬爹地[鸡]

$sql="select * from table1";
        $result=mysqli_query($conn,$sql);
            while($rs=mysqli_fetch_array($result)){
            $uid=$rs['id'];
            $num=$rs['numbers']+1;
            echo "$num"."<br />";
            $sql="UPDATE table1 SET numbers = $num where id=$uid";
            $sql=mysqli_query($conn,$sql);

大家讲道理

In foreach, multiply by 0.01 and then add the original value

ringa_lee

select finds the data, then traverses the data, and performs the operation of multiplying by 0.01 in foreach

I don’t know if you can understand it like this, I hope it can help you

  • reply I seem to have also used foreach to write. At that time, it seemed that the result of the last data * 0.01 was updated to the entire column, so the previous data was incorrect. Can you post the code so I can learn from it?
    玛莎拉蒂 author 2017-08-19 12:14:02
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template