Hi Everyone,

I have been trying to solve this for a day now, and I need some assistance, since I am not resolving this myself.

I have am trying to get all the records for teachers, and I want to loop thru the Subjects and Grades for each teacher and put them in an array.

Here is the table teachesclass table.

I am trying to get all the records for (ContactId = 2, in this case) and want to get the GradeLevelId for each SubjectArea.

Here is my code so far:

$Subjects = array(); //initialize the array
$query = "SELECT SubjectArea, GradeLevelID
FROM teachesclass
WHERE ContactId = '2' 
ORDER BY SubjectArea, GradeLevelId";

$result = mysql_query($query) or die (mysql_error() );
while ( $row = mysql_fetch_array( $result )) {
				$SubjectArea = $row['SubjectArea'];
				$GradeLevelID = $row['GradeLevelID'];
				$Subjects[][$SubjectArea] = $GradeLevelID;
}

foreach( $Subjects as $subjects) {
			foreach( $subjects as $key => $value ) {
						echo '<input type="checkbox" id="chk" name="SubjectTaught[' . $key . ']"
tabindex="' . $x . '" value="SubjectTaught ' . $value . '"';
						if ( !empty( $Subjects[$key] ) ) {
										echo ' checked';
						}
						echo '>';
			}
}

What I am getting back is: returned array values.

What I am trying to do is a foreach on SubjectArea[5], then SubjectArea[17] and check the ID's for each checkbox (see my code above.)

I hope I am clear here, and really appreciate any help, since I am totally stuck on this.

Thanks,
Don

    Write a Reply...