0

In my Models :

function input()
{
    $vendor = $this->input->post('vendor');
    for($i=1;$i<=$vendor;$i++)
    {
        for($j=1;$j<=$vendor;$j++)
        {
            $delivery[$j] = $this->input->post('delivery_1_'.$j.'_'.$i);
            $totalsatu[$i]  = array_sum($delivery);
        }
        for($k=1;$k<=$vendor;$k++)
        {
            $delivery[$k] = $this->input->post('delivery_1_'.$k.'_'.$i);
            $totaldua[$i] = $totalsatu[$i] / $delivery[$k];
        }
    }
    return array
    (
        'result1' => $totalsatu,
        'result2' => $totaldua
    );
}

and in my views,i call the $result1 and $result2 but I keep getting the following error like this :

Message: Division by zero

Filename: models/core.php

Line Number: 113

Here is the line number of 113 :

$totaldua[$i] = $totalsatu[$i] / $delivery[$k];
  • 2
    maybe you get that error because you're really trying to divide by zero – Fabio Antunes Mar 05 '13 at 15:43
  • 3
    `$totaldua[$i] = $delivery[$k] ? $totalsatu[$i] / $delivery[$k] : 0;` – Andrew Mar 05 '13 at 15:43
  • so check what value `$delivery[$k]` has at that point. maybe it's a string that gets coerced into a 0 "for your convenience" – Marc B Mar 05 '13 at 15:48
  • To make your life 100% easier, rename your form inputs. Try or such. It'll come back to the server as an array! – 000 Mar 05 '13 at 15:52
  • @joeframbach i've named all of the forms with unique name and getting back with an array,like your suggestions,but when i giving back the results into the views,i get that error :) – user2136356 Mar 05 '13 at 15:57

0 Answers0