这个错误有问题


Having a problem with this error

我得到这个错误。警告:mysql_num_rows()期望参数1是在C:'xampp'htdocs'inc'class.core.php第34行

if(mysql_num_rows(mysql_query("SHOW COLUMNS FROM ".$table." LIKE '".$column."'")) == 1)
    return TRUE;
else
    return FALSE;

This

mysql_query("SHOW COLUMNS FROM ".$table." LIKE '".$column."'")

显然不是返回资源,而是返回一个布尔值。手册会告诉你(我想)如果发生错误它会返回false。

因此查询返回了一个错误....为了清楚起见,单独运行而不是在一行中运行。像这样运行

mysql_query("SHOW COLUMNS FROM ".$table." LIKE '".$column."'") or die("error")

在手册中查找如何将mysql错误放在die() .

mysql_query()返回false。这意味着SQL查询不返回任何行作为结果。您应该将代码修改为

$result = mysql_query("SHOW COLUMNS FROM ".$table." LIKE '".$column."'");
if($result){
  $number_rows = mysql_num_rows($result);
  echo "The table has $number_rows columns with this name";
} else {
  echo "No columns with this name";
}