dongmo20030416 2013-01-30 17:34
浏览 19

非法字符串偏移,Print_R显示正确的值? [关闭]

I am getting these errors:

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

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

However, I check with print_r() what values I can call and get this:

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

So why isn't it letting me call approved?

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'];
  • 写回答

1条回答 默认 最新

  • dto52236 2013-01-30 17:37
    关注
    $avatar = $avatar['picture'];
    $avatarApproved = $avatar['approved'];
    

    The first line overrwrites $avatar with the value of $avatar['picture'], so $avatar is no longer an array when you execute the second line; and you're doing the same with $title in the subsequent query result

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line