search

Home  >  Q&A  >  body text

Update one column of data in the table

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.

玛莎拉蒂玛莎拉蒂2688 days ago1425

reply all(3)I'll reply

  • 玛莎拉蒂

    玛莎拉蒂2017-08-20 23:39:20

    $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);

    reply
    0
  • 大家讲道理

    大家讲道理2017-08-19 14:45:17

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

    reply
    0
  • ringa_lee

    ringa_lee2017-08-19 11:49:38

    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
    0
  • 玛莎拉蒂

    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?

    玛莎拉蒂 · 2017-08-19 12:14:02
  • Cancelreply