I need to know where problem

Can youany one help me

I have table contain grade of student i need to convert grade to A+,A,…etc

I try this but not save result in database i need to know where problem

help me please



$asse = mysql_query("SELECT Grade FROM studentgrade") or die("SELECT Error: ".mysql_error());
$STAssessment ;
while($row = mysql_fetch_array($asse))
{

Grade=$row ;
$query2="UPDATE studentgrade if(Grade>=95)  { SET Assessment="A+"} 
elseif(Grade>=90)  { SET Assessment="A"} 

elseif(Grade>=85)  { SET Assessment="B+"} 
elseif(Grade>=80 )  { SET Assessment="B"}
 
elseif(Grade>=75)  { SET Assessment="C+"} 
elseif(Grade>=70)  )  { SET Assessment="C"} 

elseif(Grade>=65)  { SET Assessment="D+"} 
else(Grade>=60)  { SET Assessment="D"} 
else  { SET Assessment="A"} 

endif

WHERE Grade IS NOT NULL ";

$row++;

}
<?php

$sql = array();

$sql[] = 'update grades set grade = "A+" where score >= 95 and score <= 100';
$sql[] = 'update grades set grade = "A" where score >= 80 and score < 95 ';
$sql[] = 'update grades set grade = "B" where score >= 70 and score < 80';

foreach($sql as $query) {
    mysql_query($query, $con);
}
?>

Set the correct limits for each sql query.

the correct syntax is

UPDATE studentgrade 
   SET Assessment = CASE WHEN Grade>= 95 THEN 'A+'
                         WHEN Grade>= 90 THEN 'A'
                         WHEN ...
                         ELSE 'F' END

you don’t need to use php at all

:slight_smile:

I use this but not save result in database

Instead of copypasting an example, maybe you should think what to adjust? The hint is there, it’s easy to read - you should find your way around it without being served everything for your school project :slight_smile:

replace the … with the other grade criteria and then either run the query directly in a sql window of your sql gui or run the query in php if it needs to be part of a php application.