Hi all,
I am trying to write a piece of code that will search a database table to retrieve all StudentID's that have a specific module code present in their row, and then use these studentID's to retrieve their first and last names from another table.
My PHP code is as follows:
<?php
$username = "user_02015072";
$password = "password";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("db_02015072",$dbh)
or die("Could not select first_test");
$results = mysql_query("SELECT * FROM student WHERE StudentId = (SELECT StudentId FROM modules WHERE Mod_Id1 = 'SE3S04' OR Mod_Id2 = 'SE3S04' OR Mod_Id3 = 'SE3S04' OR Mod_Id4 = 'SE3S04' OR Mod_Id5 = 'SE3S04')");
while ($row = mysql_fetch_array($results,MYSQL_ASSOC))
{
print "ID: ".$row{'StudentId'}."<br>"." First Name: ".$row{'Stud_FName'}."<br>"." Last Name: ".$row{'Stud_SName'}."<br>"."<br>";
}
mysql_close($dbh);
?>
...and results in the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\Students\02015072\SE3S04_AvancedInternetDevelopment\Assignment_2\part_2.php on line 19
Can anyone help me out please? I'm sure the solution is simple, but I can't see it!
Many Thanks,
dai.hop