hi..
I got problem in retrieving data from database.
The problem happen when the data too big and it take too long to load the data.
In fact produce php runtime error.
What is the solution for this?any anybody can help?
here is the code. The code is correct but it cause runtime error when trying load to the page.It work only for little data only.

<SCRIPT LANGUAGE="JavaScript">
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
</script>
<?php
ini_set('max_execution_time', 3600); // 1 hour
//ini_set('mysql.connect_timeout', 3600);
//ini_set('max_input_time',3600);

$sqlComs = "SELECT b.component_id FROM qla_score_weightage a,qla_ref_weightage b
WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '1'
AND a.score_id = '$project_id' AND a.status = '1' ORDER BY b.weightage_id";

$rs2s=$db->Execute($sqlComs);
echo $sqlComs; ?>
<div id="title" align="center"> Summary Score of Assessment By Project </div>
<div><a onclick="MM_openBrWindow('fpdf16/slipverifyscore.php?score=<?php echo $project_id;?>','','location=yes,scrollbars=yes,resizable=yes,width=1000,height=800')" href="" >Print Report </a> | <a onclick="MM_openBrWindow('fpdf16/sijil.php?score=<?php echo $project_id;?>','','location=yes,scrollbars=yes,resizable=yes,width=1000,height=800')" href="" >Print Certtficate </a></div><br>
<table align ="center" width="700" class="tbldata">

<tr><td align ="left" class = "row03" >Component</td><td class = "row03" >Element/Sub Element</td><td class = "row03" >Ratio Compliance</td><td class = "row03" >Weightage Compliance(%)</td><td class = "row03" >Score (%)</td></tr>
<?php
while(!$rs2s->EOF){

$coms = $rs2s->fields[0];
$ratioCom=cal_ratio_com($coms,$project_id);
$weCom=get_wcomplainceCom2($project_id,$coms);
echo '<tr><td align ="left" class = "row04" >'.component_name($coms).'</td><td class = "row04" ></td><td class = "row04" >'.round($ratioCom,3).'</td><td class = "row04" >'.round($weCom,2).'</td><td class = "row04" >'.round(get_scoreCom($project_id,$coms)round($weCom,2),2).'</td></tr>';
$sqlEles = " SELECT b.element_id FROM qla_score_weightage a,qla_ref_weightage b ,qla_ref_element c
WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '2'
AND c.element_id = b.element_id AND c.component_id = '$coms'
AND a.score_id = '$project_id' AND a.status = '1'
order by b.element_id";
//echo $sqlEles;
$rsEles=$db->Execute($sqlEles);
while(!$rsEles->EOF){
$eles = $rsEles->fields[0];
$ratio=cal_ratio_ele2($coms,$eles,$project_id);
//$we=round(get_weigtageEleBy($project_id,$coms,$eles),2);
$we = get_wcomplainceEle2($project_id,$eles,$coms);
if(check_subELE($eles)==0){
echo '<tr><td class = "row06"></td><td class = "row06" valign = "top">'.element_name($eles).'</td><td class = "row06"><b>'.round($ratio,2).'</b></td><td class = "row06">'.round($we,2).'</td><td class = "row06">'.round(round($ratio,3)
round($we,3),2).'</td></tr>';
}else{
echo '<tr><td class = "row06"></td><td class = "row06" valign = "top">'.element_name($eles).'</td><td class = "row06"></td><td class = "row06">'.round($we,3).'</td><td class = "row06"></td></tr>';

}

$sqlEleSubs = " SELECT b.sub_element_id FROM qla_score_weightage a,qla_ref_weightage b ,qla_ref_sub_element c
WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '3'
AND c.sub_element_id = b.sub_element_id AND c.element_id = '$eles'
AND a.score_id = '$project_id' AND a.status = '1' ORDER BY b.sub_element_id";
$rsEleSubs=$db->Execute($sqlEleSubs);
//echo $sqlEleSubs;

// echo '<tr><td class = "row06"></td><td valign = "top" class = "row06" ></td><td>';

while(!$rsEleSubs->EOF){
$sub_eles=$rsEleSubs->fields[0];
if(isset($sub_eles)AND $sub_eles!=""){
$subwe =get_wcomplainceSub2($project_id,$sub_eles,$eles);
//$subwe =get_weigtageSubEleBy($project_id,$eles,$sub_eles);
//echo $ub_we = $subwe$we;
//echo $subwe.'-'.$we;
$subratio = cal_ratio_noloc2($eles,$sub_eles,$project_id);
$sub=$subwe
$we;
echo '<tr><td class="row10"></td><td class="row10" >'.sub_element_name($sub_eles).'</td><td class="row10">'.round($subratio,3).'</td><td class="row10">'.round($sub,2).'</td><td class="row10">'.round(round($sub,3)*$subratio,2).'</td></tr>';
} //include('apps/qlassic/fscore/fdefect3.php');
echo '</td>';
$rsEleSubs->MoveNext();
}
// echo '</tr></table>';

// echo '</td></tr>';

//$rsLocs->MoveNext();
// }

$rsEles->MoveNext();
}

$rs2s->MoveNext();
}
?>
</table>

    nodoubt;10980908 wrote:

    hi..
    I got problem in retrieving data from database.
    The problem happen when the data too big and it take too long to load the data.
    In fact produce php runtime error.
    What is the solution for this?any anybody can help?
    here is the code. The code is correct but it cause runtime error when trying load to the page.It work only for little data only.

    <SCRIPT LANGUAGE="JavaScript">
    function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
    }
    </script>
    <?php
    ini_set('max_execution_time', 3600); // 1 hour
    //ini_set('mysql.connect_timeout', 3600);
    //ini_set('max_input_time',3600);

    $sqlComs = "SELECT b.component_id FROM qla_score_weightage a,qla_ref_weightage b
    WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '1'
    AND a.score_id = '$project_id' AND a.status = '1' ORDER BY b.weightage_id";

    $rs2s=$db->Execute($sqlComs);
    echo $sqlComs; ?>
    <div id="title" align="center"> Summary Score of Assessment By Project </div>
    <div><a onclick="MM_openBrWindow('fpdf16/slipverifyscore.php?score=<?php echo $project_id;?>','','location=yes,scrollbars=yes,resizable=yes,width=1000,height=800')" href="" >Print Report </a> | <a onclick="MM_openBrWindow('fpdf16/sijil.php?score=<?php echo $project_id;?>','','location=yes,scrollbars=yes,resizable=yes,width=1000,height=800')" href="" >Print Certtficate </a></div><br>
    <table align ="center" width="700" class="tbldata">

    <tr><td align ="left" class = "row03" >Component</td><td class = "row03" >Element/Sub Element</td><td class = "row03" >Ratio Compliance</td><td class = "row03" >Weightage Compliance(%)</td><td class = "row03" >Score (%)</td></tr>
    <?php
    while(!$rs2s->EOF){

    $coms = $rs2s->fields[0];
    $ratioCom=cal_ratio_com($coms,$project_id);
    $weCom=get_wcomplainceCom2($project_id,$coms);
    echo '<tr><td align ="left" class = "row04" >'.component_name($coms).'</td><td class = "row04" ></td><td class = "row04" >'.round($ratioCom,3).'</td><td class = "row04" >'.round($weCom,2).'</td><td class = "row04" >'.round(get_scoreCom($project_id,$coms)round($weCom,2),2).'</td></tr>';
    $sqlEles = " SELECT b.element_id FROM qla_score_weightage a,qla_ref_weightage b ,qla_ref_element c
    WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '2'
    AND c.element_id = b.element_id AND c.component_id = '$coms'
    AND a.score_id = '$project_id' AND a.status = '1'
    order by b.element_id";
    //echo $sqlEles;
    $rsEles=$db->Execute($sqlEles);
    while(!$rsEles->EOF){
    $eles = $rsEles->fields[0];
    $ratio=cal_ratio_ele2($coms,$eles,$project_id);
    //$we=round(get_weigtageEleBy($project_id,$coms,$eles),2);
    $we = get_wcomplainceEle2($project_id,$eles,$coms);
    if(check_subELE($eles)==0){
    echo '<tr><td class = "row06"></td><td class = "row06" valign = "top">'.element_name($eles).'</td><td class = "row06"><b>'.round($ratio,2).'</b></td><td class = "row06">'.round($we,2).'</td><td class = "row06">'.round(round($ratio,3)
    round($we,3),2).'</td></tr>';
    }else{
    echo '<tr><td class = "row06"></td><td class = "row06" valign = "top">'.element_name($eles).'</td><td class = "row06"></td><td class = "row06">'.round($we,3).'</td><td class = "row06"></td></tr>';

    }

    $sqlEleSubs = " SELECT b.sub_element_id FROM qla_score_weightage a,qla_ref_weightage b ,qla_ref_sub_element c
    WHERE a.weightage_id = b.weightage_id AND b.weightage_type_id = '3'
    AND c.sub_element_id = b.sub_element_id AND c.element_id = '$eles'
    AND a.score_id = '$project_id' AND a.status = '1' ORDER BY b.sub_element_id";
    $rsEleSubs=$db->Execute($sqlEleSubs);
    //echo $sqlEleSubs;

    // echo '<tr><td class = "row06"></td><td valign = "top" class = "row06" ></td><td>';

    while(!$rsEleSubs->EOF){
    $sub_eles=$rsEleSubs->fields[0];
    if(isset($sub_eles)AND $sub_eles!=""){
    $subwe =get_wcomplainceSub2($project_id,$sub_eles,$eles);
    //$subwe =get_weigtageSubEleBy($project_id,$eles,$sub_eles);
    //echo $ub_we = $subwe$we;
    //echo $subwe.'-'.$we;
    $subratio = cal_ratio_noloc2($eles,$sub_eles,$project_id);
    $sub=$subwe
    $we;
    echo '<tr><td class="row10"></td><td class="row10" >'.sub_element_name($sub_eles).'</td><td class="row10">'.round($subratio,3).'</td><td class="row10">'.round($sub,2).'</td><td class="row10">'.round(round($sub,3)*$subratio,2).'</td></tr>';
    } //include('apps/qlassic/fscore/fdefect3.php');
    echo '</td>';
    $rsEleSubs->MoveNext();
    }
    // echo '</tr></table>';

    // echo '</td></tr>';

    //$rsLocs->MoveNext();
    // }

    $rsEles->MoveNext();
    }

    $rs2s->MoveNext();
    }
    ?>
    </table>

    Any suggestion for alternative way instead of using while loop..because it too slow when loading much data from database.

      Running queries in loops is your problem here, that will alwys be the most inefficient way to do it. Any query that you run in a loop could and should be included in the outer query and then processed in nested loops.

      I can't help ypu with the query you need to write because I can't see the sql in all that code. If you extract the sql and post it along wiht your table structure I could help you with it.

      The timeout can be overcome by increasing the max execution time, but that does not mean that you should not restructure the queries and loops.

        Write a Reply...