<?php
ob_start();
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

$maindb = "demdmain";
$trandb = 'demdtran';

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$getpmain = mysqli_query($conn, "SELECT vouchno FROM `$maindb` where year = '$myyear' and section = 'P' ") or die(mysqli_error($conn));

while ($row = mysqli_fetch_array($getpmain)) {
    $vouchno = $row['vouchno'];

    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$vouchno'") or die(mysqli_error($conn));
    $nofpack = 0;
    while ($ftran = mysqli_fetch_array($gettran)) {
        $subname = $ftran['subjcode'];
        $subject = $ftran['subjname'];
        $srno = $ftran['srno'];
        
        $first = $ftran['pq1'];
        $second = $ftran['pq2'];
        $third = $ftran['pq3'];
        $fourth = $ftran['pq4'];
        
//        $pq5 = $ftran['pq5'];
//        $pq6 = $ftran['pq6'];
//        $pq7 = $ftran['pq7'];
//        $pq8 = $ftran['pq8'];
//        $pq9 = $ftran['pq9'];
//        $pq10 = $ftran['pq10'];
//        $pqrelm = $ftran['pqrelm'];


        if ($first < 10) {
            $first = 0;
        } else {
            $nofpack++;
        }

        if ($second < 10) {
            $second = 0;
        } else {
            $nofpack++;
        }

        if ($third < 10) {
            $third = 0;
        } else {
            $nofpack++;
        }

        if ($fourth < 10) {
            $fourth = 0;
        } else {
            $nofpack++;
        }

//        if ($pq5 < 10) {
//            $pq5 = 0;
//        } else {
//            $nofpack++;
//        }
//
//        if ($pq6 < 10) {
//            $pq6 = 0;
//        } else {
//            $nofpack++;
//        }
//
//        if ($pq7 < 10) {
//            $pq7 = 0;
//        } else {
//            $nofpack++;
//        }
//
//        if ($pq8 < 10) {
//            $pq8 = 0;
//        } else {
//            $nofpack++;
//        }
//
//        if ($pq9 < 10) {
//            $pq9 = 0;
//        } else {
//            $nofpack++;
//        }
//
//        if ($pq10 < 10) {
//            $pq10 = 0;
//        } else {
//            $nofpack++;
//        }
//        
//        
//        if ($pqrelm < 10) {
////            $pq10 = 0;
//        } else {
//            $nofpack++;
//        }
        
        
    }

    mysqli_query($conn, "update `$maindb` set nopack = '$nofpack' WHERE `vouchno` = '$vouchno' ") or die(mysqli_error($conn));
}
browse('done');

