简体   繁体   English

使用查询语言,mysql,php更新一行

[英]Updating a row with query language, mysql, php

I have a basic question for you experts, 专家们,我有一个基本问题,

I want to update a row in mysql database by using the User_Id of an entry. 我想通过使用条目的User_Id更新mysql数据库中的一行。 I created User_Id as auto increment, primary key. 我创建了User_Id作为自动增量主键。 Now for the last user I calculated its necessary variables, now I want to add that variable to the last user's necessary column through its User_id. 现在,对于最后一个用户,我计算了它的必要变量,现在,我想通过其User_id将该变量添加到最后一个用户的必要列中。

The name of the variable I want to add is $improvement. 我要添加的变量的名称为$ improvement。 I wrote the code below, however I dont now how to do that depending on its User_Id. 我在下面编写了代码,但是现在不根据其User_Id来执行此操作。

$sql = "
UPDATE users 
SET Improvement='$improvement'
WHERE ... )
";  

mysql_query($sql, $accounts);

I dont know what to write to the "..." part in the code. 我不知道写什么到代码中的“ ...”部分。 Please give me feedback if you see a problem in my question. 如果您在我的问题中遇到问题,请给我反馈。 I can give my table if you need. 如果您需要,我可以给我桌子。

mysql updating last inserted id mysql更新最后插入的id

I guess I found the answer in that link: 我想我在那个链接中找到了答案:

$sql = "
UPDATE users 
SET Improvement='$improvement'
WHERE User_id = LAST_INSERT_ID() )
";  

However I am not sure if "SET Improvement='$improvement'" part is the correct syntax 但是我不确定“ SET Improvement ='$ improvment'”部分的语法是否正确

If your user_id is primary index then you can use 如果您的user_id是主索引,则可以使用

$sql = " UPDATE users SET Improvement='$improvement' order by user_id DESC limit 1 ) "; $ sql =“通过user_id DESC限制1)更新UPDATE SET SET ='$ improvement'

mysql_query($sql, $accounts); mysql_query($ sql,$ accounts);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM