Question

creating a file for statistic, i'm having this error:

Internal Server Error

Division by zero

An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.

Thank you.

How can I solve this problem? This is the code:

    $theme = Yii::app()->theme->name;
echo CHtml::cssFile(Yii::app()->getBaseUrl(true).'/public/themes/'.$theme.'/css/jquery.jqplot.min.css');
echo CHtml::scriptFile(Yii::app()->getBaseUrl(true).'/public/themes/'.$theme.'/js/jquery.jqplot.min.js');
echo CHtml::scriptFile(Yii::app()->getBaseUrl(true).'/public/themes/'.$theme.'/js/jqplot.donutRenderer.min.js');
echo CHtml::scriptFile(Yii::app()->getBaseUrl(true).'/public/themes/'.$theme.'/js/jqplot.pieRenderer.min.js');
?>
<div class="row-fluid">
    <div class="well">
        <table>
            <tr>
                <td width="50%"><h1>Booking progress</h1><div id="flight" style="height:300px; width:500px;"></div></td>
                <td width="50%"><h1>Slot reservation progress</h1><div id="slot" style="height:300px; width:500px;"></div></td>
            </tr>
        </table>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
  var dataf = [
    ['Free to book', <?php echo floor(100 - $progress * 100); ?>],['Booked flights', <?php echo floor($progress * 100); ?>]
  ];
  var datas = [
    ['Free slots', <?php echo floor(100 - $sprogress * 100); ?>],['Reserved slots', <?php echo floor($sprogress * 100); ?>]
  ];
  var fplot = jQuery.jqplot ('flight', [dataf],
    {
      seriesDefaults: {
        renderer: jQuery.jqplot.PieRenderer,
        rendererOptions: {
          showDataLabels: true,
          dataLabels: 'percent'
        }
      },
      legend: { show:true, location: 's' }
    }
  );
  var splot = jQuery.jqplot ('slot', [datas],
    {
      seriesDefaults: {
        renderer: jQuery.jqplot.PieRenderer,
        rendererOptions: {
          showDataLabels: true,
          dataLabels: 'percent'
        }
      },
      legend: { show:true, location: 's' }
    }
  );
});
</script>

This is the controller

public function actionProgress()
    {
        $flc = FlightModel::model()->count();
        $bc = BookModel::model()->count();
        $progress = $bc / $flc;

        $slc = SlotModel::model()->count();
        $sc = SlotreserveModel::model()->count();

        $sprogress = $sc / $slc;
        $this->render('progress', array('progress' => $progress, 'sprogress' => $sprogress));
    }
}
Was it helpful?

Solution

Well, you do this

$progress = $bc / $flc;
$sprogress = $sc / $slc;

Either $flc or $slc or both are 0. Probably you are searching for a record that is not there.

Anything divided by 0 is infinity => that exact error.

You can probably change those 2 lines to

$progress = $flc > 0 ? $bc / $flc : 0;
$sprogress = $slc > 0 ? $sc / $slc : 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top