SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    PHP Code:

    $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++;



  2. #2
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?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.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    the correct syntax is
    Code:
    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    the correct syntax is
    Code:
    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


    I use this but not save result in database

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by flower.pink19 View Post
    I use this but not save result in database
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •