WHERE conditions when populating field select options in PHP

WHERE conditions when populating field select options in PHP

stuartsjb-icrstuartsjb-icr Posts: 59Questions: 12Answers: 0

Is it possible to use a WHERE condition when populating select option fields with the server-side script?

I've followed the Where Conditions guide but get a "Call to undefined method DataTables\Editor\Field::where()" error from the PHP.

if (!empty($_POST['moduleID'])) {
    $moduleID = ($_POST['moduleID']);
} else {
    echo "No ModuleID provided";
    die();
}

if (!empty($_POST['academicYearID'])) {
    $academicYearID = ($_POST['academicYearID']);
} else {
    echo "No AcademicYearID provided";
    die();
}

...

Field::inst('SAQScore.StudentID')
->options('Student', 'StudentID', 'StudentID1')
->where( function ( $q ) {
   $q->where('Student.StudentID', '(SELECT StudentID FROM ModuleRegistration WHERE ModuleID = :moduleID AND AcademicYearID = :academicYearID)', 'IN', false);
   $q->bind( ':moduleID', $moduleID );
   $q->bind( ':academicYearID', $academicYearID );
})

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,431Questions: 1Answers: 10,048 Site admin
    Answer ✓

    Yes. The fourth parameter of the Field->options() method can be used to specify a WHERE condition. The documentation for it is available here.

    Allan

  • stuartsjb-icrstuartsjb-icr Posts: 59Questions: 12Answers: 0

    Thanks for the link! Despite the new search feature I still struggle to find the documentation I'm looking for sometimes. :smile:

This discussion has been closed.