You may use an ajax call.
In a question of type "short text" you enter the call
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
$.post('https://www.myServer.de/getTeacher.php' , { myclass:"{Q1Class}"},function(data) {
$('#question{QID} input[type="text"]').val(data)
});
});
</script>
This is a prototype of a call.
In your script "getTeacher.php" you do your queries and return the teachers.
Now the teachers are stored in this questions and you can use them in your survey.
This is possible.
But: What is the number of classes and the number of teachers?
There might be better, shorter ways to do this with built-in features.
So, please, provide a realistic scheme (number of classes, total number of teachers, number of teachers/class (average).
Joffm