Jump to content

Error in Populating data


Ponel

Recommended Posts

@Barand @All help me out

This is my code

$sql_mee ="SELECT yearid
, semesterid
, regno
, subjectid
, rank
, total
, grade
, comment
FROM (     
   SELECT yearid
        , semesterid
        , subjectid
        , @seq := CASE WHEN yss <> @prev THEN 1
                      ELSE @seq + 1
                      END as seq
        , @rank := CASE WHEN total = @prevtot THEN @rank
                        ELSE @seq
                        END as rank
        , @prevtot := total as total
        , @prev := yss as yss
        , regno
        , armsLevelId                                            -- added 
   FROM (
           SELECT yearid
                , semesterid
                , subjectid
                , concat(yearid, armsLevelId, semesterid, subjectid) as yss
                , regno
                , total
                , armsLevelId                                   -- added 
           FROM subject_position
           ORDER BY yearid, armsLevelId, semesterid, subjectid, total DESC
        ) sorted
        JOIN (SELECT @prev := '', @seq := 0, @rank := 0, @prevtot := 0) as init
) ranked
JOIN
grade ON total BETWEEN grade.lomark AND grade.himark
WHERE regNo='$_GET[name]'                                                   -- A  
and armsLevelId='$levelid'                                          --   D 
and semesterid='$sem'                                               --    E 
and yearid='$odun'                                             --     D   
ORDER BY subjectid";
  
$query_mee = mysqli_query($con, $sql_mee);
$data_sub_pos = array();
    while($row_mee = mysqli_fetch_array($query_mee)){
        $yearid_me = $row_mee["yearid"];
        $semesterid_me = $row_mee["semesterid"];
        $regNo_me = $row_mee["regNo"];
        $subjectid_me = $row_mee["subjectid"];
        $rank_me = $row_mee["rank"];
        $total_me = $row_mee["total"];
        $grade_me = $row_mee["grade"];

         $data_sub_pos[] = $rank_me;       
                
           
    }
   
 
/*End of Subject Position Ranking*/         
         
         $sql = "select * from dummy where regid='$regno' and armsLevelId='$levelid' and yearid='$odun' and semesterid='$sem' group by subjectid";
         $result = mysqli_query($con,$sql); 
                while ($row_query=mysqli_fetch_array($result)){
                    $RegNo=$row_query["regid"]; 
                    $subject_id=$row_query["subjectid"];
                    $level_id=$row_query["armsLevelId"]; 
                    $semester=$row_query["semesterid"];
                    $session=$row_query["yearid"]; 
                    $fca=$row_query["firstCA"];
                    $sca=$row_query["secondCA"];
                    $exam=$row_query["exam"];
                    $total =$row_query["total"];
                    $grade =$row_query["grade"];
                    $comment =$row_query["comment"];
                
                //subject
                    $query_sub=mysqli_query($con,"select * from subject where id='".$subject_id."'");
             
                    while ($row_sub=mysqli_fetch_array($query_sub)){
                        $r_sub = $row_sub["subject_name"];
                    }
                    
                //level    
                    $query_level=mysqli_query($con,"select * from armslevel where id='".$level_id."'"); 
                    while ($row_level=mysqli_fetch_array($query_level)){
                        $r_level = $row_level["Armslevel"];
                    }
                
                
                //semester   
                    $query_semester=mysqli_query($con,"select * from semester where id='".$semester."'");
                        while ($row_semester=mysqli_fetch_array($query_semester)){
                            $r_semester = $row_semester["term"];
                        }
                 
                 //session     
                    $query_year=mysqli_query($con,"select * from year where id='".$session."'");
                            while ($row_year=mysqli_fetch_array($query_year)){
                                $r_year = $row_year["session"];
                            }
                
                
                  //student details
                        $query_reg=mysqli_query($con,"select * from promotion where regNo='".$RegNo."'");
                            while ($row_reg=mysqli_fetch_array($query_reg)){
                                $reg_ID = $row_reg["id"];
                                $reg_title = $row_reg["title"];
                                $reg_Regno = $row_reg["regNo"];
                                $reg_firstName = $row_reg["firstname"];
                                $reg_middleName = $row_reg["middleName"];
                                $reg_lastName = $row_reg["lastName"];
                                $reg_gender = $row_reg["gender"];
                                $reg_houseID = $row_reg["houseid"];
                                $reg_profile_pic = $row_reg["passport"]; 
                                $reg_level_id=$row_reg["armslevelid"]; 
                                $reg_semester=$row_reg["semesterid"];
                                $reg_session=$row_reg["yearid"];
                                $reg_nationality=$row_reg["nationality"];
                                $reg_stateID=$row_reg["stateID"];
                                $reg_localgovtID=$row_reg["localgovtID"];
                                $reg_phone=$row_reg["phone"];
                                $reg_email=$row_reg["email"];
                                $reg_signup_date=$row_reg["signup_date"];
                               // $reg_status=$row_reg["status"];
                                
                                //echo "select * from promotion where regNo='".$RegNo."' and armslevelid='$level_id' and arms='$arms' and yearid='$session'";
                            }
                            
                            
                          
                            
                            
                
         for ($pos=0; $pos<count($data_sub_pos); $pos++) {
                        if(!empty($data_sub_pos[$pos])){
                            $position = $data_sub_pos[$pos];   
                            $position = $position;
                        }else{
                            echo "Error Occured"; 
                        }
        }  
               
                     
                $outputdata .="<tr>
                                <td>$sn</td>
                                <td>$r_sub</td>
                                <td>$fca</td>
                                <td>$sca</td>
                                <td>$exam</td>
                                <td>$total</td>
                                <td>$position</td>
                                <td>$grade</td>
                                <td>$comment</td>
                                
                                </tr>";
                
                $sn++;
            }


Note: the position column is populating the last data. the position column should populate 1st, 8th, 7th, 3rd the last data (3rd is populated). 

thanks for your help in advance.

position.PNG

Link to comment
Share on other sites

By now you should have learned to place code inside a code block!

I'm happy try and help. Any data tables I already have from you are several years out of date and does not include the following tables used in your code:

  • subject_position
  • dummy
  • arms_level
  • promotion

I would, therefore, require an up-to-date DB dump. (I'll PM you with my email address).

Also - what MySQL version are you using?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.