0

嗨,我有一个功能是:

public function getpopularAction()
{
    $businessReviewMapper = new Application_Model_Mapper_BusinessReviewsMapper();
    $result = $businessReviewMapper->getTotalPopular();

    for ($i = 0; $i < count($result); $i++)
    {
        $rotd[$i] = $businessReviewMapper->getROTD($result[$i]['review_id']);     

        for ($j = 0; $j < count($rotd); $j++)
        {
            $rotd[$j]['u_img'] = $this->view->getLoginUserImage(
                $rotd[$j]['social_id'], $rotd[$j]['login_type'], null, null, large
            );
        }
     }

     print_r($rotd); 
     exit;
}

我得到的结果是:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [review_id] => 161
                    [review_desc] => tgi goooood....................
                    [user_id] => 2
                    [rating] => 3
                    [review_date] => 20121022203529
                    [name] => zlippr
                    [social_id] => 12345678
                    [login_type] => facebook
                    [user_unique_name] => zlippr
                    [city] => Kuala Lumpur
                    [business_name] => TGI Friday Kuala Lumpur
                )

            [u_img] => /public/images/image_not_found.png
        )
)

我不知道问题出在哪里,但是u_img没有正确获取,不确定数组循环是否正确执行。

4

2 回答 2

0

不知道内循环是干什么用的。如果您尝试检索与每个 rotd 对应的 loginuserimage,则需要执行以下操作:

    for ($i = 0; $i < count($result); $i++)
    {
       $rotd[$i] = $businessReviewMapper->getROTD($result[$i]['review_id']);     

       $rotd[$i]['u_img'] = $this->view->getLoginUserImage(
            $rotd[$i]['social_id'],$rotd[$i]['login_type'],null,null,large);
    }
于 2012-10-24T08:06:37.727 回答
0

通过查看您的输出,您的结果在数组的第二层内,这意味着您应该将变量替换getLoginUserImage

$rotd[$i]['social_id'],$rotd[$i]['login_type'] 

$rotd[$i][0]['social_id'],$rotd[$i][0]['login_type']
于 2012-10-24T08:15:16.180 回答