Jump to content

[SOLVED] help with basic query


gammaman

Recommended Posts

I need help figuring out why my query is not updating the way it should.

 

foreach($Grade as $itm =>$value)
    {   

       print_r($value);
       mysql_query("Update Rcourse set Grade = '$value'  where Grade < 'A' AND StudentID='$itm' AND  CourseID='{$_SESSION['checkaddGrades']['course']}'")
          or die(mysql_error()); 
       
     
     
    } # end of foreach

 

Here is the array you are seeing from the foreach

 

Array ( [1] => A ) Array ( [311] => C+ )

 

I want the Grade to be set to either A or C+ depeding upon the studentID which is the key inside the [].

When I run it assigns the word array to just the first occurance of the query.

Link to comment
https://forums.phpfreaks.com/topic/103399-solved-help-with-basic-query/
Share on other sites

Yeah, that is what I thought it would be...it's just oddly structured...this should work for you though:

 

<?php
foreach($Grade as $set){
  foreach($set as $itm =>$value){
    print "Giving student $itm grade $value\n";
    mysql_query("Update Rcourse set Grade = '$value'  where Grade < 'A' AND StudentID='$itm' AND  CourseID='{$_SESSION['checkaddGrades']['course']}'")
      or die(mysql_error()); 
  }
}
?>

 

Not sure why you have "WHERE Grade < 'A'" either...but that is how you can get your array values properly

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.