Jump to content

Division by 0 error


googlit

Recommended Posts

Hi can any body give me an idea why i am receiving the following errors from my script?

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 29

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 44

 

Warning: Division by zero in C:\xampp\htdocs\Practice\page.php on line 50

 

script is:

<?php
include_once "include/globals.php";

if (isset($_GET['cat-id'])) {
        $id = $_GET['cat-id'];
        }
?>

<?php 

        
        
        //Get database Results
        $result = mysql_query("SELECT * FROM Products WHERE is_active = 1 AND catagory_id = $id ") or die(mysql_error());
        
        if(mysql_num_rows($result)===0)
{
    $output = "No records found.\n";
}
else
{
    $output = "<table>\n";
    //keeps getting the next row until no more records
    $recNo = 0;
    while($row = mysql_fetch_array($result))
    {
        $recNo++;
        //Start new row when needed
        if($recNo%$max_columns==1)
        {
            $output .= "<tr>\n";
        }
        //Create TD for record
        $output .= "<td><div class=\"table-bg\">";
        $output .= "<div class=\"title\">{$row['Name']}</div>";
        $output .= "<div class=\"image\">";
        $output .= "<a href=\"product_detail.php?id=\"><img src=\"{$row['image']}\" width=\"100\" alt=\"\" border=\"0\"></a>";
        $output .= "</div>";
        $output .= "<div class=\"tag_line\">{$row['Tag_Line']}</div>";
        $output .= "<div class=\"price\">Now Only: £{$row['Website_Price']}</div>";
        $output .= "<div class=\"prod-footer\"><a href=\"product_detail.php?id={$row['ID']}\">more info</a></div>";
        $output .= "</div></td>\n";
        //Close row when needed
        if($recNo%$max_columns==0)
        {
            $output .= "</tr>\n";
        }
    }
    //Close final row if needed
    if($recNo%$max_columns!=0)
    {
        $output .= "</tr>\n";
    }
    $output .= "<table>\n";
}
?>


    <div id="main">
    <?php echo $output; ?>
    </div>
    <div class="table-bg"></div>



    

Link to comment
https://forums.phpfreaks.com/topic/213889-division-by-0-error/
Share on other sites

that link DOES show $max_columns being set to 3; HOWEVER in your current codes does NOT reflect that. Hence the current script has $max_columns 'undefined/set' which gives it a value of ZERO which results in your error.

 

Try adding $max_columns = 3 to your current script

Link to comment
https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113291
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.