Php 如何将一个数字除以两组值。。?

Php 如何将一个数字除以两组值。。?,php,mysql,Php,Mysql,我正在根据用户输入的from date和to date执行一些除法操作 Mysql查询返回特定日期的总和,我必须将总和除以该月的总天数。但问题是用户提供了两组输入,即起始日期和两个日期 如何将执行查询得到的和除以2组值 下面是我的php代码: <input id="monthIpone" name="monthone" type="month"> /*enters starting month*/ <input id="monthIptwo" name="mont

我正在根据用户输入的
from date
to date
执行一些除法操作

Mysql查询返回特定日期的总和,我必须将总和除以该月的总天数。但问题是用户提供了两组输入,即起始日期和两个日期

如何将执行查询得到的和除以2组值

下面是我的php代码:

   <input id="monthIpone" name="monthone" type="month"> /*enters starting month*/
    <input id="monthIptwo" name="monthtwo" type="month"> /*enters ending month*/

      <input type="button"  value="submit" id="submit" class="btn btn-primary" name="submit" onclick="callphp()"> /*submit*/

下面是我的解决方案,它刚刚移动到foreach循环中。

移动代码之前

   foreach($marray as $object)
     {
            $obj = new stdClass();
            $time = $object->timestamp;
            $obj->timestamp=$time;

            $total = $object->sum;
            $avg = $total/6;
            $cuf = $avg /((72*245)*(24*$days));/*need to caculate for 
                                                 both from date and two 
                                                 date*/
            $obj->cuf = $cuf;
            array_push($marray,$obj);

    }
在for each循环中移动代码后

      foreach($marray as $object)
        {
                $obj = new stdClass();
                $time = $object->timestamp;
                //var_dump($time);

                /*to find no of days in a month*/
                $split = explode('-', $time);
                $year = $split[0];
                $month = $split[1];
                $days = cal_days_in_month(CAL_GREGORIAN, $month,$year);
                //echo "$days"."<br/>";

                $obj->timestamp=$time;

                $total = $object->sum;
                $avg = $total/6;

                $cuf = $avg /((72*245)*(24*$days));
                $obj->cuf = $cuf;
                array_push($marray,$obj);

        }
foreach($marray作为$object)
{
$obj=新的stdClass();
$time=$object->timestamp;
//var_dump($时间);
/*在一个月内找不到天*/
$split=爆炸('-',$time);
$year=$split[0];
$month=$split[1];
$days=每月的计算天数(计算公历,$month,$year);
//回显“$days”。
; $obj->timestamp=$time; $total=$object->sum; $avg=$total/6; $cuf=$avg/((72*245)*(24*245天)); $obj->cuf=$cuf; 阵列推送($marray,$obj); }
警告:当使用
mysqli
时,您应该使用和将用户数据添加到查询中。不要使用字符串插值或串联来完成此操作,因为您已经创建了严重的错误。切勿将
$\u POST
$\u GET
或任何用户数据直接放入查询中,如果有人试图利用您的错误进行攻击,这可能非常有害。从日期和到日期表示一个范围。在你的问题中,你说“那一天的总和”是哪一天?从日期,到日期,还是今天的日期?@Solan Thrasher。。。用户在这两种情况下都输入月份和年份。从……到。。。。我需要计算该月的天数,并用这两个值进行除法。。。。。
      foreach($marray as $object)
        {
                $obj = new stdClass();
                $time = $object->timestamp;
                //var_dump($time);

                /*to find no of days in a month*/
                $split = explode('-', $time);
                $year = $split[0];
                $month = $split[1];
                $days = cal_days_in_month(CAL_GREGORIAN, $month,$year);
                //echo "$days"."<br/>";

                $obj->timestamp=$time;

                $total = $object->sum;
                $avg = $total/6;

                $cuf = $avg /((72*245)*(24*$days));
                $obj->cuf = $cuf;
                array_push($marray,$obj);

        }