1

I want to update single row base on id, i have questions table and there is column question_id, which has unique date for each row. Now i want to update that row column based on that question_id. I have code written below, but not getting success. It created New Record not update old record. I want to update old record. I have tried both ParseObject and ParseQuery but not getting success.

      $query = new ParseObject("question");
      $query->equalTo("question_id", "2");
      $query->set("correct_percentage", "55.5");
      $query->save();

1 Answer 1

1

You should load the object in question first, manipulate the data and then save it. Your current code, as you already noticed, simply creates new objects each time it is run.

// Fetch the question object where question_id == 2
$query = new ParseQuery("question");
$query->equalTo("question_id", "2");
$question = $query->first();

// .. optionally verify that $question has a value ...

// Manipulate the object and save it
$question->set("correct_percentage", "55.5");
$question->save();
Sign up to request clarification or add additional context in comments.

2 Comments

Björn Kaiser, thanks for help i have tried this, but its show error. Fatal error: Call to a member function set() on a non-object, on this line => $question->set("correct_percentage", $percentage);
Does the question you are querying actually exist in your database?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.