googlit Posted September 20, 2010 Share Posted September 20, 2010 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> Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 20, 2010 Share Posted September 20, 2010 where are you setting the value of $max_columns? Quote Link to comment Share on other sites More sharing options...
Username: Posted September 20, 2010 Share Posted September 20, 2010 >divide by zero somewhere in script >expect positive result >ABOVE THE LAW Quote Link to comment Share on other sites More sharing options...
googlit Posted September 20, 2010 Author Share Posted September 20, 2010 hi the code was used from an example provided on this post: http://www.phpfreaks.com/forums/index.php/topic,310186.msg1464976.html#msg1464976 Quote Link to comment Share on other sites More sharing options...
litebearer Posted September 20, 2010 Share Posted September 20, 2010 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 Quote Link to comment Share on other sites More sharing options...
googlit Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks very much matey Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.