Warning: Division by zero in

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yash321
Forum Newbie
Posts: 3
Joined: Sat Jul 10, 2010 4:55 pm

Warning: Division by zero in

Post by yash321 »

Warning: Division by zero in /home/catch/domains/mysite.com/public_html/engine/modules/news_r.php on line 33

Code: Select all

<?php
/*
---------------------------------------------
DataLife Engine, Word Press, Joomla And Drupal
---------------------------------------------
http://www.cms-pedia.com
---------------------------------------------
*/

if(!defined('DATALIFEENGINE')){die("Hacking attempt!");}

$kol = 100; // êîëè÷åñòâî ñèìâîëîâ â âûâîäå êîðîòêîé íîâîñòè â áëîêå
$maxWidth = 150; // ìàêñèìàëüíàÿ øèðèíà èçîáðàæåíèÿ 
$maxHeight = 150; // ìàêñèìàëüíàÿ âûñîòà èçîáðàæåíèÿ 

$db->query("SELECT COUNT(*) FROM ".PREFIX ."_post");
$row = $db->get_row();

$offset = mt_rand(0, $row['COUNT(*)']-1);
$db->query("SELECT * FROM ".PREFIX ."_post LIMIT 1 OFFSET $offset");

$row = $db->get_row();
preg_match_all( '|<img[\s]+src[\s]*=[\s]*\"([^\"]*)\"|', $row['short_story'], $matches );

if ($matches[1][0] != '') {
$imageinfo = @getimagesize($matches[1][0]);  
$width  = $imageinfo[0];
$height = $imageinfo[1];

if ($width > $height) {
   $fltRatio = floatval($maxWidth / $width);
 } else {
   $fltRatio = floatval($maxHeight / $height);
}
 
$intNewWidth  = intval($fltRatio * $width);
$intNewHeight = intval($fltRatio * $height);
	
$pic = '<center><img src="'.$matches[1][0].'" width="'.$intNewWidth.'" height="'.$intNewHeight.'"></center>';
} else {$img = '';}

$news_r = '<b>'.ucfirst($row['title']).'</b>';
if ($pic != '') {$news_r .= '<br>'.$pic;}
$story = strip_tags($row['short_story']);
if ($config['allow_alt_url'] == "yes") {
if ($row['flag'] AND $config['seo_type']) {
if ($row['category'] AND $config['seo_type'] == 2) {
$full_link = $config['http_home_url'].get_url($row['category'])."/".$row['id']."-".$row['alt_name'].".html";
} else {
$full_link = $config['http_home_url'].$row['id']."-".$row['alt_name'].".html";
} } else {
$full_link = $config['http_home_url'].date('Y/m/d/', $row['date']).$row['alt_name'].".html";
} } else { $full_link = $config['http_home_url']."index.php?newsid=".$row['id']; }
if (strlen($story) > 0) {$news_r .= '<br>'.substr($story,0,$kol).'...<a href="'.$full_link.'">Read More</a>';}
?>

here is the whole news_r.php ..

Plz help me in solving this problem

Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Warning: Division by zero in

Post by requinix »

Remove the @ a couple lines up, look at the error message, and guess what you should do.
yash321
Forum Newbie
Posts: 3
Joined: Sat Jul 10, 2010 4:55 pm

Re: Warning: Division by zero in

Post by yash321 »

can u tell me more ?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Warning: Division by zero in

Post by requinix »

Maybe. Depends if you've tried to do anything for yourself first.
User avatar
morris520
Forum Commoner
Posts: 60
Joined: Thu Sep 18, 2008 8:56 pm
Location: Manchester UK

Re: Warning: Division by zero in

Post by morris520 »

Hi,
If you are not afraid of being lazy, you could try this way:
check the values of each variable where it involves the "/" because the error comes from a divider = 0;
99.9% sure you got a bug in your code and the value of divider set to 0.
Thanks
yash321
Forum Newbie
Posts: 3
Joined: Sat Jul 10, 2010 4:55 pm

Re: Warning: Division by zero in

Post by yash321 »

Hold on Guys !

I m not a php coder if i will do anything that will make situation more critical

as u can see this it is a DataLife Engine, Word Press, Joomla And Drupal script

I m running a site and where it give this error sometime

Warning: Division by zero in /home/catch/domains/mysite.com/public_html/engine/modules/news_r.php on line 33

so i posted that news_r php script i don't know what a single line means

..

Thnx
Post Reply