php - 我的 PHP MySQL while 循环不返回结果

标签 php mysql loops while-loop

<?php
$sqls = mysql_query("SELECT weight FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);
$ct = mysql_query ("COUNT * '$sqls'");

if ($ct > 0) {
   while ($row = mysql_fetch_array($sqls));{
      $weight = $row["weight"];
      echo "C" . $weight;
    }}
else {
  echo "No stats found";
}
?>

即使表中有数据,也会输出“未找到统计信息”。

<?php
$sqls = mysql_query("SELECT weight FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);
$ct = mysql_num_rows($sqls);

if ($ct > 0) {
   while ($row = mysql_fetch_array($sqls));{
      $weight = $row["weight"];
      echo "C" . $weight;
    }}
else {
  echo "No stats found";
}
?>

这不会返回任何内容。完全没有 echo 。

我已经检查过它是否可以通过使用来访问:

<?php
   $sqls = mysql_query("SELECT weight FROM $usertablestats")
   or die ("Query failed: " . mysql_error() . " Actual query: " . $query);

   $row = mysql_fetch_array($sqls);

   echo $row;
?>

它确实返回第一个条目。

最佳答案

while 中有分号:

while ($row = mysql_fetch_array($sqls));{
//should be
while ($row = mysql_fetch_array($sqls)){

这会引起问题吗

关于php - 我的 PHP MySQL while 循环不返回结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8109787/

相关文章:

php - 如何在 PHP 中比较日期?

sql - Django select_related() 用于使用模型和过滤器进行多连接查询

java - 我如何将这段代码转换为循环?

php - 禁用所有主流浏览器中的浏览器按钮和 URL 地址栏?

php - 在 laravel 中通过迁移创建包含几行的表

javascript - 使用两个 for 循环与 if (k in obj) 迭代对象

vba - 在简单的循环中错过一些东西

php - 如何使用 jquery 在动态添加的表行上创建计算

PHPExcel 一次在多个工作表上设置相同的属性、内容等

php - 使用数据库中的 DateTime() 格式化部分未知日期?