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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.