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()
总是返回一个数组 此外,您可能希望在打印之前和之后回显“”,以便在浏览器中对其进行良好格式化。此外,您可能希望在打印之前和之后回显“”,以便在浏览器中对其进行良好格式化