Current location: Hot Scripts Forums » Programming Languages » PHP » Help with error message


Help with error message

Reply
  #1 (permalink)  
Old 03-16-10, 05:29 PM
cflpool cflpool is offline
New Member
 
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Help with error message

Hi,

I know nothing about PHP so bear with me!
I run a football pool and a friend was helping me with the PHP side of the site. Well for what every reason he has stopped helping me and now I am getting this error message. cflpigskinpickem.com

Warning: Division by zero in /home/cflpmcom/public_html/10/includes/dbStandings.php on line 29

on the page Standings.php this is were the error shows up

PHP Code:

<?php

$tableBackColour 
"DDDDDD";
$tableCellPadding "2";
$tableCellSpacing "2";
$tableBackColour "DDDDDD";
$fontColour "000000";

require_once(
'includes/dbConnect.php');
require_once(
'includes/dbStandings.php');

echo 
"<style type=\"text/css\">\n";
echo 
"table,td,th {\n";
echo 
"background-color: #" $tableBackColour ";\n";
echo 
"color: #" $fontColour ";\n";
echo 
"border-spacing: " $tableCellSpacing "px;\n";
echo 
"padding: " $tableCellPadding "px;\n";
echo 
"}\n";
echo 
"</style>\n\n";

echo 
"<table border=\"0\" align=\"center\">\n";
echo 
"<TR ALIGN=\"center\">\n";
echo 
"<TD><B>Rank</B></TD>\n";
echo 
"<TD><B>Name</B></TD>\n";
echo 
"<TD COLSPAN=\"3\"><B>Record</B></TD>\n";
echo 
"<TD><B>Average</B></TD>\n";
echo 
"</TR>\n";
$lastRight 0;
foreach (
$standings as $key => $value) {
    echo 
"<TR ALIGN=\"center\" VALIGN=\"middle\">\n";
    if (
$lastRight == $value['right']) {
        echo 
"<TD>-</TD>\n";
    } else {
        echo 
"<TD>" $key "</TD>\n";
    }
    echo 
"<TD ALIGN=\"left\"><a href=\"picks.php?which=" $value['pid'] . "\">" $value['name'] . "</a></TD>\n";
    echo 
"<TD ALIGN=\"right\">" $value['right'] . "</TD>\n";
    echo 
"<TD>-</TD>\n";
    echo 
"<TD ALIGN=\"left\">" $value['wrong'] . "</TD>\n";
    echo 
"<TD ALIGN=\"right\">" $value['average'] . "%</TD>\n";
    echo 
"</tr>\n";
    
$lastRight $value['right'];
}
echo 
"</TABLE>\n";
?>

includes/dbStandings.php

<?php
require_once('includes/dbGames.php');
require_once(
'includes/dbPicks.php');

$x 1;
foreach (
$picks as $key => $value) {
    
$right 0;
    
$wrong 0;
    
$standings[$x]['pid'] = $key;
    
$standings[$x]['name'] = $value['name'];
    foreach (
$games as $key2 => $value2) {
        
$pick $key2 9;
        if (
$value2['hs'] > $value2['vs']) {
            if (
$value['picks'][$pick] == $value2['ht']) {
                ++
$right;
            } else {
                ++
$wrong;
            }
        } elseif (
$value2['hs'] < $value2['vs']) {
            if (
$value['picks'][$pick] == $value2['vt']) {
                ++
$right;
            } else {
                ++
$wrong;
            }
        }
    }
    
$standings[$x]['right'] = $right;
    
$standings[$x]['wrong'] = $wrong;
    
$standings[$x]['average'] = 100 round($right / ($right $wrong), 2);
    ++
$x;
}

for (
$x=1$x<=sizeof($standings); $x++) {
    for (
$y=1$y<=sizeof($standings); $y++) {
        if (
$standings[$x]['right'] > $standings[$y]['right']) {
            
$temp $standings[$x];
            
$standings[$x] = $standings[$y];
            
$standings[$y] = $temp;
        }
    }
}
?>
If there is anything more you need let me know.

Thanks

Last edited by wirehopper; 03-16-10 at 06:05 PM. Reason: PHP tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-16-10, 06:06 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
PHP Code:

if (($right $wrong) != 0
$standings[$x]['average'] = 100 round($right / ($right $wrong), 2); 
else
$standings[$x]['average']=0
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
cflpool (03-18-10)
  #3 (permalink)  
Old 03-17-10, 04:24 PM
cflpool cflpool is offline
New Member
 
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks for the answer, but what does it mean?
Were do I put this?
I am a PHP dummy

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-17-10, 06:06 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Find this line:

$standings[$x]['average'] = 100 * round($right / ($right + $wrong), 2);

Replace it with the four lines posted above.

The problem is that in one case, $right+$wrong was zero, probably for the first run of the script. Division by zero is impossible - so PHP reports the error and stops. The code I posted tests for the zero, and if $right+$wrong is zero, it assigns 0 to the average.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
cflpool (03-18-10)
  #5 (permalink)  
Old 03-18-10, 05:39 PM
cflpool cflpool is offline
New Member
 
Join Date: Mar 2010
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
cool!!
It looks like it works.
Thanks Very Much!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP upload prob minority ASP 1 06-27-05 09:35 AM


All times are GMT -5. The time now is 08:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.