预示着麻烦

时间:2012-04-21 22:51:52

标签: php html ajax

我想显示每个唯一ID的XML请求中的图像。应该显示总共三个图像,但我得到相同的图像三次。

这里的ID正确存储:

    $simIds = array(
    "id1" => $similarObject->place[0]['place_id'],
    "id2" => $similarObject->place[1]['place_id'],
    "id3" => $similarObject->place[2]['place_id'],
);

这是我的foreach循环:

foreach ($simIds as $foo) {
    $simPhotoFile = $photoUrl.$foo;
    $simPhotoObject = simplexml_load_file($simPhotoFile);
    $simPhotoSrc = array (
        'src1' => $simPhotoObject->photos->photo_set->square,
        'src2' => $simPhotoObject->photos->photo_set->square,
        'src3' => $simPhotoObject->photos->photo_set->square,       
    );  
}

相关的HTML:

<p><img src="<?= $simPhotoSrc['src1'] ?>" alt="Image load failed" /><img src="<?= $simPhotoSrc['src2'] ?>" alt="Image load failed" /><img src="<?= $simPhotoSrc['src3'] ?>" alt="Image load failed" /></p>

我不确定此刻我做错了什么,或者是否有更好的方法可以解决这个问题。谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

$simPhotoSrc = array();
foreach ($simIds as $foo) {
    $simPhotoFile = $photoUrl.$foo;
    $simPhotoObject = simplexml_load_file($simPhotoFile);
    $simPhotoSrc[] = $simPhotoObject->photos->photo_set->square
}

HTML:

<p><img src="<?= $simPhotoSrc[0] ?>"/><img src="<?= $simPhotoSrc[1] ?>" /><img src="<?= $simPhotoSrc[2] ?>" /></p>