开发者

foreach loop not showing data

I am having a strange issue with the output of data for my foreach loop. The loop is not showing the data for the $image->thumbname,$description or $id but the print_r($get_images); works fine

Print_r Output:

Array ( [0] =&g开发者_StackOverflow社区t; 
    Array ( [id] => 1 
            [description] => testing 
            [imagename] => test.jpg 
            [thumbname] => test_thumb.jpg 
) )

View:

<?php if(is_array($get_images)): ?>
    <? print_r($get_images); ?>
        <?php foreach($get_images as $image): ?>
        <img src ="<?=base_url()?>includes/uploads/gallery/thumbs/<?=$image->thumbname?>" alt="<?= $image->description?>"> <a href="deleteimage/<?=$image->id?>">Delete</a>
        <?php print_r($image); ?>
    <?php endforeach; ?>
<?php endif; ?>


youre using -> to access the array contents youre supposed to use []

<?php if(is_array($get_images)): ?>
    <? print_r($get_images); ?>
        <?php foreach($get_images as $image): ?>
        <img src ="<?=base_url()?>includes/uploads/gallery/thumbs/<?= $image['thumbname'] ?>" alt="<?= $image['description'] ?>"> <a href="deleteimage/<?= $image['id'] ?>">Delete</a>
        <?php print_r($image); ?>
        <?php endforeach; ?>
<?php endif; ?>


That should be $image["thumbname"] and not $image->thumbname.


You have an array from what I can tell:

$image['thumbname']
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜