我有以下代码:
<?
include"mysql.php";
$getusers= mysqli_query ("select count(*) as cnt from users",$c);
$totalusers= mysqli_fetch_array ($getusers);
$totalusers=$totalusers['cnt'];
$getusers= mysqli_query ("select * from users",$c);
$totalmoney=0;
while($usr= mysqli_fetch_array ($getusers))
{
$totalmoney=$totalmoney+$usr['total_earned'];
}
$getoffers= mysqli_query ("select count(*) as cnt from offers where active=1",$c);
$ocnt= mysqli_fetch_array ($getoffers);
$ocnt=$ocnt['cnt'];
print"<p>Total Offers: $ocnt<br>Total Members: $totalusers<br>Total Earned: \$$totalmoney</p>";
?>
它仍然给我这个错误:
警告:mysqli_query()要求参数1为mysqli,第48行/home/u705139137/public_html/header.php中给出的字符串
警告:mysqli_fetch_array()要求参数1为mysqli_result,在第49行的/home/u705139137/public_html/header.php中给出null
警告:mysqli_query()期望参数1为mysqli,第51行/home/u705139137/public_html/header.php中给出的字符串
警告:mysqli_fetch_array()要求参数1为mysqli_result,在第53行的/home/u705139137/public_html/header.php中给出null
警告:mysqli_query()要求参数1为mysqli,第57行/home/u705139137/public_html/header.php中给出的字符串
警告:mysqli_fetch_array()要求参数1为mysqli_result,在第58行的/home/u705139137/public_html/header.php中给出null
我做错了什么?
答案 0 :(得分:0)
更改你的mysqli_query,如下所示
<?
include"mysql.php";
$getusers= mysqli_query ($c,"select count(*) as cnt from users");
$totalusers= mysqli_fetch_array ($getusers);
$totalusers=$totalusers['cnt'];
$getusers= mysqli_query ("select * from users",$c);
$totalmoney=0;
while($usr= mysqli_fetch_array ($getusers))
{
$totalmoney=$totalmoney+$usr['total_earned'];
}
$getoffers= mysqli_query ("select count(*) as cnt from offers where active=1",$c);
$ocnt= mysqli_fetch_array ($getoffers);
$ocnt=$ocnt['cnt'];
print"<p>Total Offers: $ocnt<br>Total Members: $totalusers<br>Total Earned: \$$totalmoney</p>";
?>
答案 1 :(得分:0)
这样做
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$getusers= mysqli_query ($mysqli, "select count(*) as cnt from users");