I keep on getting this error "Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in" from both of my while loop conditions. Can anyone review my code and let me know what I'm doing wrong?
<html>
<head>
<title>Task # 4 - Test Page</title>
</head>
<body>
<?php
$link = mysql_connect('127.0.0.1');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}// open connection
mysql_select_db('task4', $link); // database selection
$totalTrainees = 0;
$q1 = mysql_query("select trainerID from trainer", $link); //get all trainerID
while($row=mysql_fetch_row($q1))
{
echo $row[0]." ";
$v1 = "select courseID, count(courseID) as totalCourses from courses where trainerID=$row[0]";
$q2 = mysql_query($v1);
while($row1=mysql_fetch_row($q2))
{
echo $row1[0]." ";
$v2 = "select count(attendanceStatus) from trainee where $row1";
$totalTrainees += $totalTrainees;
}//end while 2
echo $totalTrainees;
}//end while 1
mysql_close($link); //close connection to db
?>
</body>
</html>