[英]My PHP MySQL while loop does not return results
<?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";
}
?>
这什么也不会返回。 完全没有回声。
我已经检查过是否仅使用以下命令进行访问:
<?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 ($row = mysql_fetch_array($sqls));{ //should be while ($row = mysql_fetch_array($sqls)){
是造成问题的吗
<?php
$sqls = mysql_query("SELECT * FROM $usertablestats")
or die ("Query failed: " . mysql_error() . " Actual query: " . $query);
if (mysql_num_rows($sqls)!=0) {
while ($row = mysql_fetch_assoc($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);
int $ct = 0;
while ($row = mysql_fetch_array($sqls)){
$weight = $row["weight"];
echo "C" . $weight;
$ct++;
}
if ($ct == 0) {
echo "No stats found";
}
?>
如果它不起作用,请确保$usertablestats
具有正确的值。
尝试这个。
while ($row = mysql_fetch_array($sqls,MYSQL_ASSOC)){
$weight = $row["weight"];
echo "C" . $weight;
$ct++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.