Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:36:44+00:00 2026-06-11T06:36:44+00:00

When I pass the season end date as a variable to this function I

  • 0

When I pass the season end date as a variable to this function I get this error: Warning: Division by zero

function win_percentage($season_start, $season_end)
{
    $wins = mysql_query("SELECT COUNT(result) FROM scorecards WHERE result = 'Won' AND gamedate >= $season_start AND gamedate <= $season_end;");
    $losses = mysql_query("SELECT COUNT(result) FROM scorecards WHERE result = 'Lost' AND gamedate >= $season_start AND gamedate <= $season_end;");
    $winstotal = mysql_fetch_array($wins);
    $lossestotal = mysql_fetch_array($losses);
    $resultgames = $winstotal['COUNT(result)'] + $lossestotal['COUNT(result)'];
    $winratio = ROUND(($winstotal['COUNT(result)'] / $resultgames),2) * 100;
    return $winratio;
}
echo win_percentage('2012-01-01', '2012-09-10')

OUTPUT: Warning: Division by zero

However, when I put a date value for the season end directly in the function it works perfectly. The only difference between these to blocks of code is the end of lines 3 and 4, everything else is identical. Why can’t I pass season_end to this function without the error being thrown?

function win_percentage($season_start, $season_end)
{
    $wins = mysql_query("SELECT COUNT(result) FROM scorecards WHERE result = 'Won' AND gamedate >= $season_start AND gamedate <= '2012-12-31';");
    $losses = mysql_query("SELECT COUNT(result) FROM scorecards WHERE result = 'Lost' AND gamedate >= $season_start AND gamedate <= '2012-12-31';");
    $winstotal = mysql_fetch_array($wins);
    $lossestotal = mysql_fetch_array($losses);
    $resultgames = $winstotal['COUNT(result)'] + $lossestotal['COUNT(result)'];
    $winratio = ROUND(($winstotal['COUNT(result)'] / $resultgames),2) * 100;
    return $winratio;
}
echo win_percentage('2012-01-01', '2012-09-10')

OUTPUT: 57%

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:36:46+00:00Added an answer on June 11, 2026 at 6:36 am

    You should put ' before and after your date values when you use them in a query: AND gamedate >= '$season_start' AND gamedate <= '$season_end'

    You should also use mysqli.

    You should also avoid keeping dates as strings in your database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I pass a variable $foo to a function. This input variable might be an
I pass a function an xml variable: node . function (node){ //how do I
I am attempting to pass an Eigen::Vector4d into an function like this: Matrix3d quat2DCM(Vector4d
When pass a variable to a function, why the function only gets a copy/duplicate
I pass an object literal to a function like this: pre( {model:'MUserTry'} ); I
I pass a string into this function: function linkify($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a
Pass a integer 2 to this function and then return a integer which is
I pass a Date object to a method which calls date.getHours() or any other
i pass parameter as productid, i check in productrelated table whether this product related
I want to pass variable defaults to my templates in case of the actual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.