I have a while loop that outputs a list of classes. In the classes database the teacher name is determined by the teachers ID in the users database.
Here is my database structure.
Classes Database
-----------------------------
ID CLASS TEACHER
1 product design 3
User Database
-----------------------------
ID NAME
3 John Doe
So when listing my classes I need it to convert "3" into "John Doe".
This is my current code:
<?php
$classdetails = mysql_query("SELECT * FROM class");
while($class = mysql_fetch_array($classdetails)) {
$marklist_class = $class['class'];
$marklist_teacher = $class['teacher']; //This is a userid
//------Somewhere here i need to get the userid and look it up in the user database
if($marklist_class=="") {
} else {
echo $marklist_class . ' ' . $marklist_teacher;}
}
}
?>
I understand just putting another mysql query there will lower performance and is not advised, so how would I look up the user database for every row without adding a query into the while loop.
Thank you.