2017-08-19 12 views
0

セクション1の1つのマークと10の質問、セクション2の2つのマークと5つの質問、セクション3の4つのマークと5質問。総件数は20件、総数は40件です。ユーザーが試験を終えると、その結果をセクションワイズレポートを示すレポートに表示しようとしています。ここで問題となるのは、ユーザーが1つのセクションのみを試して、3つの正解を確保していると仮定すると、セクション1では3、その他の2つのセクションではレポートが必要ですが、すべてのセクションに1つのセクションの値があります。私が提示する必要があるのは、ユーザーが1つのセクションだけを試したので、「正解」3-0-0の数です。現在のところ、すべてのセクションで3つ必要です。ここでレポート内のさまざまなセクションで値が繰り返されます

は、フロントエンドのために私のコードです

<tr><td>3</td> 

        <td>Correct Answers</td> 

        <td><?php echo $rep->sectionwiseMockReport($id, $chapterId,1); ?></td> 

        <td><?php echo $rep->sectionwiseMockReport($id, $chapterId,2); ?></td> 

        <td><?php echo $rep->sectionwiseMockReport($id, $chapterId,3); ?></td> 

        <td><?php echo ($rep->sectionwiseMockReport($id, $chapterId,1)+$rep->sectionwiseMockReport($id, $chapterId,2)+$rep->sectionwiseMockReport($id, $chapterId,3)) ; ?></td> 

       </tr> 

と呼ばれている機能は、クラスの中にある、

function sectionwiseMockReport($userId, $chapterId,$section) 

{ 
    $counter1 = 0 ; 
    $counter2 = 0 ; 
    $counter3 = 0 ; 
    $total  = 0 ; 

    $result = mysql_query("SELECT question_id, option_id from tbl_result_chapter WHERE user_id = $userId AND chapter_id = $chapterId");  
     while($row = mysql_fetch_array($result)) 
     { 
      if($this->getRightOptionChapter($row['question_id']) == $row['option_id']) 
      { 
       $section = $this->idToField("tbl_question_chapter","section",$row['question_id']); 
       if($section == 1) 
       { 
        $counter1 = $counter1 + 1 ; 
       } 
       if($section == 2) 
       { 
        $counter2 = $counter2 + 1 ; 
       } 
       if($section == 3) 

       { 

        $counter3 = $counter3 + 1 ; 
       } 
      } 
     } 
      if($section == 1) 
       { 
        return $counter1; 
       } 

       if($section == 2) 
       { 
        return $counter2; 
       } 
       if($section == 3) 
       { 
        return $counter3; 
       } 
} 

そして最後に機能、

function getRightOptionChapter($questionId) 
{ 
     $result = mysql_query("SELECT * from tbl_chapter_answer a INNER JOIN tbl_chapter_options o on a.options_id = o.id WHERE a.question_id = $questionId");  
     $row = mysql_fetch_array($result);  
     return $row['options_id']; 
} 

どんな提案や助けも命を救う人になるでしょう。数日間はこれを探していたが、全く成功しなかった。

答えて

0

最後に問題が発生しました。変数$sectionはwhileループとwhileループの外側で競合を生成していました。 whileループの中で変数名を変更して素早く動作させました。

関連する問題