Problem: I am trying to query a field based on a previously retrieved ID from another table in the database. Given the id from the one table(where it is not the primary, but serves as a reference to the primary of another table), I am trying to retrieve the entry associated with that ID. I have tried numerous times but Php still returns parse errors. The top half of the code works, its just the retrieval mechanism for the second part that doesn't.
Code: Select all
mysql_select_db($database_NHSDatabase, $NHSDatabase);
$query_RecLetter = "SELECT * FROM recletter ORDER BY StudentID ASC";
$RecLetter = mysql_query($query_RecLetter, $NHSDatabase) or die(mysql_error());
$row_RecLetter = mysql_fetch_assoc($RecLetter);
$totalRows_rsRecLetter = mysql_num_rows($rsRecLetter);
mysql_select_db($database_NHSDatabase, $NHSDatabase);
$query_StudentName = sprintf("SELECT * FROM students WHERE StudentID='$row_RecLetter['StudentID']'");
$StudentName = mysql_query($query_StudentName, $NHSDatabase) or die(mysql_error());
$row_StudentName = mysql_fetch_assoc($StudentName);
$totalRows_StudentName = mysql_num_rows($StudentName);
Code: Select all
<?php echo $row_StudentName['StudentName']; ?>