gpt4 book ai didi

php - 错误 : Array to string conversion error

转载 作者:行者123 更新时间:2023-11-29 04:16:14 25 4
gpt4 key购买 nike

首先,我从我的表中随机选择 ID。那部分工作正常,但下一部分没有。下一部分是选择 ID 的行,例如如果ID是6,那么它应该选择与6相关的所有字段。

我的表是这样的:

------------------------------
|ID|Name|Email |Password|
------------------------------
|1 |Amy |H@gmail.com|jaaaaaaa|
------------------------------
|2 |Bob |1@gmail.com|haaukanm|
------------------------------
|3 |Bill|aa@mail.com|fsoji443|
------------------------------

这是我的代码:

<?php
include('connect.php');

//select a number between min id and max id
$v = "SELECT ID FROM `tblaccounts` ORDER BY RAND() LIMIT 1";
$result = mysqli_query($connection, $v);
$data2 = mysqli_fetch_array($result);
//var_dump($data2);

$c = "SELECT * FROM `tblaccounts` WHERE ID='$data2'";
$cresult = mysqli_query($connection, $c);
$data3 = mysqli_fetch_array($cresult);
var_dump($data3);
?>

最佳答案

问题在这里:

$c = "SELECT * FROM `tblaccounts` WHERE ID='$data2'";

这里 $data2 不是单个值,它是一个数组,您正试图在 WHERE 中像字符串一样比较它,这就是错误的原因。而是尝试像这样的 $data2['id']:

$c = "SELECT * FROM `tblaccounts` WHERE ID='".$data2['ID']."'";

$c = "SELECT * FROM `tblaccounts` WHERE ID=".$data2['ID'];  // Sinlge quote is not required if `ID` is `int`

关于php - 错误 : Array to string conversion error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44819309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com