I have a while loop that outputs a list of classes. In the class database, the name of the teacher is determined by the identifier of the teachers in the user database.
Here is my database structure.
Classes Database ----------------------------- ID CLASS TEACHER 1 product design 3 User Database ----------------------------- ID NAME 3 John Doe
Therefore, when listing my classes, I need to convert “3” to “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 that simply adding another mysql query will decrease performance and is not recommended, since I could search for a user database for each row without adding the query to the while loop.
Thanks.
source share