更新数据库中的最大值php mysql的列 [英] Update column in database where max value php mysql
问题描述
我在这里遇到问题.即时更新名称,其中B具有最大的价值.
I got problem here. im updating name where B has the biggest value.
所以结果是
B | name
---|------
1 |
2 |
3 | YES
但是当B列更改值时,问题是行名称为3的列名仍然有一个值.
but when column B changes value the problem is column name with row value 3 still has a value.
B | name
---|------
1 |
4 | YES
3 | YES
结果应该是.
B | name
---|------
1 |
4 | YES
3 |
如果
B | name
---|------
0 |
0 |
0 |
然后
B | name
---|------
0 |
0 |
0 |
如果
B | name
---|------
4 |
4 |
2 |
然后
B | name
---|------
4 | YES
4 | YES
2 |
这就是我想要的.
仅使用此简单代码.
$sql3 = "UPDATE products SET name='YES' ORDER BY B DESC";
推荐答案
我想您要更新表中B列为最高值的行?您肯定需要"WHERE"子句,但您还需要知道该列中的最高值.为什么不先查询数据库以从B列检索最大值?
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"
然后将B列等于此值插入数据库中吗?
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...
这篇关于更新数据库中的最大值php mysql的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!