mysql - Get specific field from a table with moodle Data manipulation API -
i want select records moodle data base id equal variable.can tell me moodle data manipulation api syntax it.
here mysql query
select question mdl_answers id=$questionid;
i have tried
$queid[]= $queid[] = $db->get_field('question_answers', 'id', array('question' => $questionid), must_exist); $true=$queid[0]; // $false=$queid[1]; //this remains empty
but gives 1 record whereas have more 1 records assosiated id.
as can see in picture record 71 , 72 have same value 48 in next column want these ids 71 , 72
get_field()
return single value.
either use get_records()
- https://docs.moodle.org/dev/data_manipulation_api#getting_an_hashed_array_of_records
$answers = $db->get_records('question_answers', array('question' => $questionid)); foreach ($answers $answer) { switch ($answer->answer) { case 'true': $true = $answer->id; break; case 'false': $false = $answer->id; break; } }
or use get_field()
this
$true = $db->get_field('question_answers', 'id', array('question' => $questionid, 'answer' => 'true')); $false = $db->get_field('question_answers', 'id', array('question' => $questionid, 'answer' => 'false'));
Comments
Post a Comment