我想在我的表中获取ID然后更新 id行是自动增量
if (isset($_POST['reply'])) {
$reply = $_POST['reply'];
$answers = $db->query("SELECT * FROM table_name");
while($answers_ = $answers->fetch_object()){
if($get_answer = $db->query("UPDATE table_name SET answer ='$reply' WHERE question_id = '$answers_->question_id' LIMIT 1")){
echo "done";
}
}
}
我知道我的代码是错误的更新所有具有相同值的行我想只更新一行
答案 0 :(得分:2)
use mysqli_insert_id()
- 返回上一个queryn
$get_answer = $db->query("UPDATE table_name SET answer ='$reply' WHERE question_id = '$answers_->question_id' LIMIT 1")
$last_id = mysql_insert_id();