gpt4 book ai didi

PHP 函数总是返回 false

转载 作者:行者123 更新时间:2023-11-30 23:02:38 25 4
gpt4 key购买 nike

我想弄清楚为什么返回的结果总是false

SQL 和 PHP 代码如下:

public function getAlbumList($userID){
$albumIDs= mysql_query("SELECT albumID FROM albumAccess WHERE userID='$userID'");
//$albums = mysql_query("SELECT albums.* FROM albums WHERE albumAccess.userID = '$userID' AND albumAcess.albumID = albums.albumID");

if($albumIDs){
$albums=array();

while($r = mysql_fetch_array($albumsIDs)){
$albums[]=mysql_query("SELECT * FROM albums WHERE albumID = '$r'");
}
return mysql_fetch_array($albums);

}else{
return false;
}

}

获取结果并将其传递给 android 应用程序的 PHP 代码是这样的:

$userID=$_POST['userID'];

$albumList = $db->getAlbumList($userID);

if($albumList){
$response["success"]=1;
$response['album']=array();
while($r = mysql_fetch_assoc($albumList)){
$response['album'][]= $r;
}

header('Content-type: text/json');
echo json_encode($response);

} else {
//album list failed to be loaded
$response["error"]=2;
$response["error_msg"]="Error Loading Album List. Please try again later.";

header('Content-type: text/json');
echo json_encode($response);
}

当我检查返回内容的日志时,我总是收到错误消息

"Error loading album list"

但是,我只有在尝试返回数组时才会得到它。如果我只是返回 true 而没有使用第二个 SQL 请求,它会返回 true。

最佳答案

您还可以尝试使用 JOIN 或 SUBQUERY:

public function getAlbumList($userID){
$albumIDs= mysql_query("SELECT *
FROM albums
WHERE albumID IN (
SELECT albumID FROM albumAccess WHERE userID='$userID'
)");

if(mysql_numrows($albumIDs) > 0){
$albums=array();

while($r = mysql_fetch_array($albumsIDs)){
$albums[] = $r;
}

return $albums;
}

return false;
}

PHP代码:

    $albumList = $db->getAlbumList($userID);

if($albumList){
$response["success"]=1;
$response['album'] = $albumList;
} else {
//album list failed to be loaded
$response["error"]=2;
$response["error_msg"]="Error Loading Album List. Please try again later.";
}
header('Content-type: text/json');
echo json_encode($response);

关于PHP 函数总是返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23300072/

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