Forum Moderators: coopster
So $classRslt has 3 records to loop through, $inputRslt has 2.
The first while loops starts using the first record from $classRslt, then hits the embedded while loop and runs through both records of $inputRslt.
So my output ends up with 2 lines containing the 2 unique class_id and the id, program_name, and room name of the first record in $classRslt then it stops and doesn't proceed with the 2nd and 3rd iterations from my $classRslt loop
What am I doing wrong?
$ids = array();
while($a = mysql_fetch_array($classRslt)){
array_push($ids,$a);
}
$iids = array();
while($a = mysql_fetch_array($inputRslt)){
array_push($iids,$a);
}
for($i=0;$i<$numClasses;$i++){
for($b=0;$b<$numInput;$b++){
if($ids[$i]['id']!= $iids[$b]['class_id']){
echo $iids[$b]['class_id']." / ";
echo $ids[$i]['id']." ".$ids[$i]['program_name']." / Room: ".$ids[$i]['room_name']."<br>";
}
}
}
It doesn't quite work the way I need it to, this is what gets returned:
20 / 18 18Program / Room: 18Room
19 / 18 18Program / Room: 18Room
20 / 19 19Program / Room: 19Room
19 / 20 20Program / Room: 20Room
What I need to be echoed is just the 18Program once, since it's the only id that doesn't match one of the class_id being output from $iids
I'm not sure how to accomplish that, any suggestions?
for($i=0;$i<$numClasses;$i++) {
if(!in_array($id[$i],$iid))
echo 'This class isn\'t in a room: ' . $id[$i] . '<br />';
}
for($b=0;$b<$numInput;$b++) {
if(!in_array($iid[$b],$id))
echo 'This room doesn\'t have a class: ' . $iid[$b] . '<br />';
}
You also don't have to use array_push - there's nothing wrong with it, but you could also use:
$ids[] = $a;