Update column in database where max value php mysql

前端 未结 2 788
温柔的废话
温柔的废话 2021-01-29 07:32

I got problem here. im updating name where B has the biggest value.

so the results are

B  | name
---|------
 1 | 
 2 | 
 3 | YES

but wh

2条回答
  •  礼貌的吻别
    2021-01-29 08:36

    I think you want to update the row in the the table where column B is the highest value? You definitely need a "WHERE" clause, but you also need to know the highest value in that column. Why don't you query the database first to retrieve the highest value from column B?

    $maxvalue = "SELECT `B` FROM products ORDER BY `B` DESC LIMIT 1"
    

    and then insert into the database WHERE the column B equals this value?

    "UPDATE products SET name='YES' WHERE B = $maxvalue"
    

    This is not complete code, just conceptual. I will clean it up and edit this answer...

提交回复
热议问题