Good day I got a warning like this :
Warning: Division by zero in C:\Documents and Settings\LT\report.php on line 122

Warning: Division by zero in C:\Documents and Settings\LT\report.php on line 220

I have this code in line 22:

$yield = ($c_output / $f_input) * 100;

and this is my code in line 220

$yield = ($sol_output / $buff_input) * 100;

my c_output is = 65.17
f_input is = 68.40

so the result should be : 95.27 but on my output is 0.00%

and my sol_output = 0.00
buff_input = 0. 00

and the result is 0.00 % which is correct but why I got this warning.

Thank you

    clearly $f_input is 0 or empty and in the other case division by zero makes the math gods cry
    if you have to do it you can suppress the warning with an @

      dagon;10968960 wrote:

      clearly $f_input is 0 or empty and in the other case division by zero makes the math gods cry
      if you have to do it you can suppress the warning with an @

      But it has a data and not zero.

      I put @ and the warning was disappear but still the Yield was wrong output

        Here i my full code

        if($_POST["start_date"])
                {
                $query = "SELECT plt_no FROM plt_transact WHERE plt_date = '" . $_POST["start_date"] . "'";
                $result_loop = mysql_query($query);
        
            $Batch_yield = 0;
            $buff_input = 0;
            $sol_output = 0;
            $loopctr = 0;
            $totalloop = 0;
        
            /***Header****/
            if($result_loop) if(mysql_num_rows($result_loop) > 0)
                {
                $totalloop = mysql_num_rows($result_loop);
        
                $plt_no = mysql_result($result_loop,0,"plt_no");
                $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_no = '$plt_no' AND d.plt_transact_id = t.plt_transact_id GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
                $result = mysql_query($query);
                if($result)
                    {
                    echo "<table cellspacing='2' style='font-family: arial narrow; font-size: 12px; border-width: 2px 2px 2px 2px; border-style: solid;'>";
        
                    echo "<tr>";
                    echo "<th class='tdclass'>PLT #</th>";
                    $total_row = mysql_num_rows($result);
                    for($ctr=0; $ctr < $total_row; $ctr++)
                        {
                        $opname = mysql_result($result,$ctr,"operation_name");
                        $i = strpos($opname," ",0);
                        $opname = substr($opname,$i);
                        echo "<th colspan='2' class='tdclass'>" . $opname . "<br />(" . mysql_result($result,$ctr,"output_unit") . ")</th>";
                        }
                    echo "<th class='tdclass'>PLT Yield</th>";
                    //echo "<th class='tdclass'>Batch Yield</th>";
                    echo "</tr>";
        
                    echo "<tr>";
                    echo "<td class='tdclass'></td>";
        
                    for($ctr=0; $ctr < $total_row; $ctr++)
                        {
                        echo "<td class='tdclass'>Input</td>";
                        echo "<td class='tdclass'>Output</td>";
                        }
        
                    echo "<td class='tdclass'>";
                    echo "</td>";
        
                    echo "</tr>";
        
                    }
                }
        
            $query = "SELECT plt_no FROM plt_transact WHERE plt_date = '" . $_POST["start_date"] . "'";
            $result_loop = mysql_query($query);               
            while($row = mysql_fetch_array($result_loop))
                {
                $loopctr += 1;
                $plt_no = $row["plt_no"];
                $query = "SELECT * FROM plt_transact WHERE plt_no = '$plt_no'";
                $result_no = mysql_query($query);
                if($result_no)
                    {
                    if(mysql_num_rows($result_no) > 0)
                        {
                        $f_input = 0;
                        $c_output = 0;
        
                        $query  = "SELECT SUM(t.input_qty) AS f_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='05 Forming' AND p.plt_no = '$plt_no'";
                        $resultyield = mysql_query($query);
                        if($resultyield)
                            {
                            if(mysql_num_rows($resultyield) > 0) $f_input = mysql_result($resultyield,0,"f_input");
                            }
        
                        $query  = "SELECT SUM(t.output_qty) AS c_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='08 Core Molding' AND p.plt_no = '$plt_no'";
                        $resultyield = mysql_query($query);
                        if($resultyield)
                            {
                            if(mysql_num_rows($resultyield) > 0) $c_output = mysql_result($resultyield,0,"c_output");
                            }
        
                        $PLT_yield = ($c_output / $f_input) * 100;
        
        
                        $query  = "SELECT SUM(t.input_qty) AS buff_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='09 Core Buffing, Insp and Sizing' AND p.plt_no = '$plt_no'";
                        $resultyield = mysql_query($query);
                        if($resultyield)
                            {
                            if(mysql_num_rows($resultyield) > 0) $buff_input = $buff_input + mysql_result($resultyield,0,"buff_input");
                            }
        
                        $query  = "SELECT SUM(t.output_qty) AS sol_output FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='10 Core Solutioning' AND p.plt_no = '$plt_no'";
                        $resultyield = mysql_query($query);
                        if($resultyield)
                            {
                            if(mysql_num_rows($resultyield) > 0) $sol_output = $sol_output + mysql_result($resultyield,0,"sol_output");
                            }
        
                        $query = "SELECT d.operation_name, SUM(d.input_qty) AS inputqty, d.input_unit, SUM(d.output_qty) AS outputqty, d.output_unit FROM traceability d, plt_transact t WHERE t.plt_no = '$plt_no' AND d.plt_transact_id = t.plt_transact_id GROUP BY d.operation_name, d.output_unit, d.input_unit ORDER BY d.operation_name";
                        $result = mysql_query($query);
                        if($result)
                            {
        
        
                            echo "<tr>";
                            echo "<td><strong>$plt_no</strong></td>";
        
                            for($ctr=0; $ctr < $total_row; $ctr++)
                              {
                                echo "<td class='tdclass'>";
                                echo number_format((mysql_result($result,$ctr,"inputqty")),2);  
                                //echo mysql_result ($result,$ctr,"inputqty");
        
                                echo "</td>";
                                echo "<td class='tdclass'>";
                                echo number_format((mysql_result($result,$ctr,"outputqty")),2);  
                               // echo mysql_result ($result,$ctr,"outputqty");
        
                                echo "</td>";
                              } 
        
                            echo "<td class='tdclass'><strong>";
                            printf ("%01.2f", $PLT_yield);
                            echo "%</strong></td>";
                            /*echo "<td>&nbsp;";
                            echo "</td>";*/
                            echo "</tr>";
        
        
                            }
                        }
                    }
                }
                $Batch_yield = ($sol_output / $buff_input) * 100;
                echo "<tr>";
                echo "<td style='text-align: right; font-weight: bold; font-family: Arial;' class = 'tdclass' colspan='";
                $loopctr = ($total_row * 2) + 2;
                echo "$loopctr'>Batch Yield:&nbsp;&nbsp;$Batch_yield%</td>";
                echo "</tr>";
                echo "</table>";               
                //echo "<div style='text-align: right; font-family: arial narrow; font-size: 12px;'><strong>Batch Yield:&nbsp;&nbsp;$Batch_yield%</strong></div>";
           }
        

          i believe php over you πŸ˜‰ it says its 0, check again, and again :p

            dagon;10968963 wrote:

            i believe php over you πŸ˜‰ it says its 0, check again, and again :p

            I put f_input = 0; but whenun my webpage the f_input boutput is not zero because in my database the data in f_input is 68.40..

            I can see any prob in my codeπŸ˜•

              dagon;10968963 wrote:

              i believe php over you πŸ˜‰ it says its 0, check again, and again :p

              I can't see...I try to check it many times.

              I try to change this code:

              $f_input = 0; into $f_input = "";

              but nothing happen..Still the warning isl there an did not compute correctly...I really need to fix this warning.

              Thank you

                your code sets $f_input to 0 then changes it based on a query, check that query is returning what you expect.

                  dagon;10968968 wrote:

                  your code sets $f_input to 0 then changes it based on a query, check that query is returning what you expect.

                  I can't see what you say...πŸ˜•

                    Can you tell me where it is?and how can i fix this warning?thank you

                      here is where you set the value:

                        $query  = "SELECT SUM(t.input_qty) AS f_input FROM traceability t, plt_transact p WHERE t.plt_transact_id = p.plt_transact_id AND t.operation_name='05 Forming' AND p.plt_no = '$plt_no'";
                                          $resultyield = mysql_query($query);
                                          if($resultyield)
                                              {
                                              if(mysql_num_rows($resultyield) > 0) $f_input = mysql_result($resultyield,0,"f_input");
                                              } 
                      
                        Write a Reply...