2 回答
TA贡献2012条经验 获得超12个赞
我已经在我的代码中添加了注释。此外,您正在使用 ,您尚未将它们声明为带有符号的变量。mysqli_connect(server, dbuser, dbpw, db)$
<?php
//Make connection with DB
$con = mysqli_connect($server, $dbuser, $dbpw, $db);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$sql = "SELECT SUM(nooftokensused) as summ FROM bidding WHERE biddedon >= DATE_FORMAT(CURRENT_DATE(), '%Y-01-01') GROUP BY biddingid";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0)
{
// Associative array
$row = mysqli_fetch_assoc($result);
echo $row["summ"];
}
else
{
echo 0;
}
// Free result set
mysqli_free_result($result);
mysqli_close($con);
?>
TA贡献1719条经验 获得超6个赞
使用 mysqli_fetch_assoc() 而不是 mysqli_num_rows()。
<?php
$conn = mysqli_connect(server, dbuser, dbpw, db);
$query = " SELECT SUM(value_sum) AS nooftokensused FROM bidding WHERE biddedon >= DATE_FORMAT(CURRENT_DATE(), '%Y-01-01') GROUP BY biddingid";
$query_run = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($query_run);
echo '<h1>'.$row['nooftokensused'].'</h1>';
?>
- 2 回答
- 0 关注
- 103 浏览
添加回答
举报