Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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 Mysqli_Php_Mysql_Mysqli - Fatal编程技术网

警告:非法字符串偏移量PHP Mysqli

警告:非法字符串偏移量PHP Mysqli,php,mysql,mysqli,Php,Mysql,Mysqli,我正在尝试使用以下代码从mysql数据库获取数据: $con = mysqli_connect('localhost', 'root', '', 'nicu'); mysqli_query($con, "set NAMES utf8"); $query = mysqli_query($con, "select * from user"); while($rows = mysqli_fetch_assoc($query)) : $rows = $rows["

我正在尝试使用以下代码从mysql数据库获取数据:

$con = mysqli_connect('localhost', 'root', '', 'nicu');
    mysqli_query($con, "set NAMES utf8");
    $query = mysqli_query($con, "select * from user");
    while($rows = mysqli_fetch_assoc($query)) :
        $rows = $rows["nicuAddress"];
        $address = $rows["nicuEmail"];
        echo "$rows<br>$address";
    endwhile;
$con=mysqli_connect('localhost','root','nicu');
mysqli_查询($con,“set NAMES utf8”);
$query=mysqli_query($con,“从用户选择*);
而($rows=mysqli\u fetch\u assoc($query)):
$rows=$rows[“nicuAddress”];
$address=$rows[“nicuEmail”];
回显“$rows
$address”; 结束时;
但每次运行此代码时,我都会收到以下警告:
警告:非法字符串偏移量


要修复此问题,我必须做哪些更改?

您正在尝试访问被覆盖的阵列的一部分。运行
$rows=$rows[“nicuAddress”]
后,您无法以数组形式访问
$address=$rows[“nicuEmail”]

解决方案

$address = $rows["nicuAddress"]; // <-- Change to address
$email = $rows["nicuEmail"]; // <-- Change to email
echo "$address<br>$email";

$address=$rows[“nicuAddress”];//不确定是否是错误的原因,但您正在覆盖循环第一行的
$rows
。这看起来不对。@AlexanderO'Mara是的,我没有注意到,谢谢