Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP显示错误_Php_Mysql - Fatal编程技术网

PHP显示错误

PHP显示错误,php,mysql,Php,Mysql,我已经创建了以下代码,但由于某种原因,它会回显数组而不是结果: <?php include("../config.php"); include("functions.php"); $count = "SELECT `monthly_slots` FROM users WHERE `username` = 'Bill'"; $count = mysql_query($count); $data = mysql_fetch_assoc($count);

我已经创建了以下代码,但由于某种原因,它会回显数组而不是结果:

<?php
    include("../config.php");
    include("functions.php");

    $count = "SELECT `monthly_slots` FROM users WHERE `username` = 'Bill'";
    $count = mysql_query($count);
    $data = mysql_fetch_assoc($count);
    echo "$data";
?>
试试这个

print_r($data);
这将输出数组的内容

mysql\u fetch\u assoc
的返回类型是数组。因此,您应该使用
print\r
查看结果

Returns an associative array that corresponds to the fetched row and moves the internal data
pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC 
for the optional second parameter. It only returns an associative array.
试试这个

print_r($data);
这将输出数组的内容

mysql\u fetch\u assoc
的返回类型是数组。因此,您应该使用
print\r
查看结果

Returns an associative array that corresponds to the fetched row and moves the internal data
pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC 
for the optional second parameter. It only returns an associative array.

这是意料之中的。您应该尝试打印($data)
这是预期的。您应该尝试
print\r($data)

print\r($data)来转储数组的内容。

mysql\u fetch\u assoc()返回一个数组,您需要使用
print\r($data)
来转储数组的内容。

如手册页所述,当您在字符串上下文中输出数组变量时(如
echo
所做的那样),它将变成
“array”

要查看数组内容,请使用或:

或者最好只访问您想要的内容:

print($data["monthly_slots"]);
正如手册页面所解释的,当您在字符串上下文中输出数组变量时(如
echo
所做的),它将变成
“array”

要查看数组内容,请使用或:

或者最好只访问您想要的内容:

print($data["monthly_slots"]);

解决方案

  • 您只需使用

    打印($data)

然而,考虑到你只是在寻找一种特定的商品,我通常不建议你这样做

  • 您还可以尝试将输出作为第一项引用(假设只有一个结果),并使用

    echo“$data[0]”

  • 您也可以简单地引用您正在使用的数组中的特定项

    echo$data['monthly_slots']。

参考文献:


    • 解决方案

      • 您只需使用

        打印($data)

      然而,考虑到你只是在寻找一种特定的商品,我通常不建议你这样做

      • 您还可以尝试将输出作为第一项引用(假设只有一个结果),并使用

        echo“$data[0]”

      • 您也可以简单地引用您正在使用的数组中的特定项

        echo$data['monthly_slots']。

      参考文献:

      使用
      print\r($data)
      打印
      $data
      数组,或对特定行使用
      $data['column\u name']
      。因为
      mysql\u fetch\u assoc()
      总是返回一个数组

      使用
      print\r($data)
      打印
      $data
      数组,或对特定行使用
      $data['column\u name']
      。因为
      mysql\u fetch\u assoc()
      总是返回一个数组

      此外,您可能希望在打印之前和之后回显“”,以便在浏览器中对其进行良好格式化。此外,您可能希望在打印之前和之后回显“”,以便在浏览器中对其进行良好格式化