0

我收到这些错误:

Warning: Illegal string offset 'approved' in C:... on line 137

Warning: Illegal string offset 'approved' in C:... on line 147

但是,我用 print_r() 检查我可以调用哪些值并得到这个:

Array (
    [0] => 3
    [id] => 3
    [1] => 3
    [user_fk] => 3
    [2] => > Jailbot 2.0
    [title] => > Jailbot 2.0
    [3] => 1
    [approved] => 1
) 

那为什么不让我打电话批准?

PHP:

$avatarQuery = "SELECT * FROM avatars WHERE user_fk = {$id} LIMIT 1";
$avatarSet = mysql_query($avatarQuery, $connection);
confirm_query($avatarSet);
$count = mysql_num_rows($avatarSet);
if($count == 1){
    $avatar = mysql_fetch_array($avatarSet);
    $avatar = $avatar['picture'];
    $avatarApproved = $avatar['approved'];
}else{
    $avatar = "images/noImage.png";
}
$titleQuery = "SELECT * FROM titles WHERE user_fk = {$id} LIMIT 1";
$titleSet = mysql_query($titleQuery, $connection);
confirm_query($titleSet);
$title = mysql_fetch_array($titleSet);
$title = $title['title'];
$titleApproved = $title['approved'];
4

1 回答 1

2
$avatar = $avatar['picture'];
$avatarApproved = $avatar['approved'];

第一行用$avatar['picture']的值覆盖了$avatar,所以执行第二行时$avatar不再是一个数组;并且您在后续查询结果中对 $title 执行相同操作

于 2013-01-30T17:37:43.197 回答