gpt4 book ai didi

php - MySQL - 显示计数结果

转载 作者:行者123 更新时间:2023-11-29 13:59:26 24 4
gpt4 key购买 nike

我只是想展示 MySQL (PHP) 中的咨询结果。代码是:

$example = mysql_query("SELECT count(*) as text FROM table WHERE name = '$name'");
$qtd = mysql_num_rows($example);
while($data = mysql_fetch_array($qtd)){
$count = $data["text"];
}

echo "<h3>($count)</h3>";

Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\Site\index.php on line 9

最佳答案

改变这个

 while($data = mysql_fetch_array($qtd)){
$count = $data["text"];
}

while($data = mysql_fetch_array($example)){
$count = $data["text"];
}

编辑:您不需要在这里执行 while 循环。

你应该这样做

     $example = mysql_query("SELECT count(*) as text FROM table WHERE name = '$name'");
$data = mysql_fetch_array($example) ;
$count = $data["text"];
echo "<h3>".$count."</h3>";

关于php - MySQL - 显示计数结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15326335/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com