Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Php mysql error Warning: Division by zero in
Old 03-13-2010, 12:50 AM Php mysql error Warning: Division by zero in
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Hi,

I am getting division by zero error in php.....please help.

Here's the code.

PHP Code:
$biz_val$row_c['biz_id'];
                        
$sql_rat="select * from tblrating where rat_biz_id = ".$row_c['biz_id']."";
                        
$result_rat mysql_query($sql_rat);
                        
$tot_rec mysql_fetch_array($result_rat);
                        
$i=$j=$d=0;
                        
//$row_rt = 0;
                    
if($tot_rec>0)
                    {        
$row_rt $tot_rec;
                        while (
$i=mysql_fetch_array($result_rat))
                        {
                            
$i++;
                            
$j$row_rt['rat_num'] + $j;
                        }    
                        
$d=$j/$i;
                      if (
$d<=1.50)
{
echo 
img1.gif;
}
if (
$d<=2.50 && $d>=1.51)
{
echo 
img2.gif;
}
}
else
{
echo 
img0.gif;

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2010, 01:54 AM Re: Php mysql error Warning: Division by zero in
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
The problem is here:
PHP Code:
                        while ($i=mysql_fetch_array($result_rat))
                        {
                            
$i++;
                            
$j$row_rt['rat_num'] + $j;
                        } 
Once the while loop terminates $i is equal to null.

Technically in PHP 0 == NULL so the line:
PHP Code:
$d=$j/$i
will always be a division by 0.

One other thing: I don't understand why you are incrementing i in the while loop; it isn't a numeric value.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-13-2010, 02:37 AM Re: Php mysql error Warning: Division by zero in
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Hi NullPointer,

now its been solved I made used a separate if condition for percentage....now its working fine.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Php mysql error Warning: Division by zero in
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.65997 seconds with 12 queries