Populating a select field without using ajax

HI,
i have two select fields. lets call select field one class, the other student. Class is not linked to any column in the database. I just created it.
select field two is called students and is of type integer (this integer is of course a foreign key).
what i want:
originally when the form loads, select field students gets loaded with all students IDs vial a lookup SELECT statement.
When i chose a class in select field class, i want to return all studentIDs that belong to that class.
I have tried this & it doesnt work:

sc_select(my_data, “select StudentsID from classprogress WHERE ClassID = {Class}”);
if ({my_data} === false)
{
echo “Access error. Message =”. {my_data_erro};
}
else
{
while (!$my_data->EOF)
{
{Student} = $my_data->fields[0];
$my_data->MoveNext();
}
$my_data->Close();
}

note above that student is a select field, its new data should be only studentIDs that belong to that particular class!
it seems to return all results and does not remove the original contents of the select field student.

i would be greatful for any hints

update: if the solution requires use of ajax then its ok…

In your Class select field properties, enable “… reload o other fields…” under Ajax Processing, and enable the field Students in the listbox.

In your students field, do this select:
“select StudentsID from classprogress WHERE ClassID = {Class}”

It’s all

EDIT: If you don’t want ajax, then you need to save class on a global an refresh your page to SELECT students field refresh

Yo the best…worked like a charm.
May you be blessed!!