Reputation: 57
I want to get ids in my table then update id row is auto increment
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";
}
}
}
I know my code is wrong its update all rows with the same value i want to update only one row
Upvotes: 0
Views: 48
Reputation: 2023
use mysqli_insert_id()
— Returns the auto generated id used in the last queryn
$get_answer = $db->query("UPDATE table_name SET answer ='$reply' WHERE question_id = '$answers_->question_id' LIMIT 1")
$last_id = mysql_insert_id();
Upvotes: 2