两个计数并在单个查询中将两个计数相除

时间:2019-03-08 14:40:36

标签: php mysql mysqli

基本上需要什么-投注数(在betDate列= $ date设置的行数)和获胜数-(在betDate = $ date列的行和返回'return'= $ Win的行数($ Win ='Win ';)然后将两个计数相除-betCount / winCount并回显结果。

count(IF(betDate ='$ Date',1,0))AS bet_count-有效

count(IF(result ='$ Win',1,0))AS win_count-不起作用。

(bet_count / win_count)AS total_count-不起作用。

仅显示错误

  

错误,mysqli_fetch_assoc()期望参数1为mysqli_result,   第467行给出的布尔值,第467行是while($ testrow =   mysqli_fetch_assoc($ testresult))

谢谢:)

PHP尝试进行计数和计算

<?php

    $connection = mysqli_connect("******", "******", "******", "******");
    if (!$connection) {
        die("Database connection failed: " . mysqli_connect_error());
    }

    $Date = '2019-03-11'; 
   $Win = 'Win';


 $testsql="SELECT 
    count(IF(betDate = '$Date', 1, 0)) AS bet_count,
    count(IF(betDate = '$Date' AND result ='$Win', 1, 0)) AS win_count,
    (bet_count / win_count) AS total_count
FROM bets";


$testresult = mysqli_query($connection, $testsql);

while ($testrow = mysqli_fetch_assoc($testresult))
{ 
    echo "<tr>";
echo "<td class='text-center'>".$testrow['total_count'] . "</td>";
echo "</tr>";
}

mysqli_close($connection);
?>
</table>
                        </div>


                    </div>
                </div> 

0 个答案:

没有答案