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> Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/ 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? Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113226 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 Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113228 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 Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113288 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 Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113291 Share on other sites More sharing options...
googlit Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks very much matey Link to comment https://forums.phpfreaks.com/topic/213889-division-by-0-error/#findComment-1113736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.