我的应用说 - 不能使用stdClass类型的对象作为数组,任何想法?

时间:2017-05-11 06:57:34

标签: php html

由于某种原因,我的应用程序给了我一个PHP错误说

  

不能在第45行使用stdClass类型的对象作为数组。

有点难过为什么会这样。任何的想法?

我一直在讨论这个问题超过一个小时了。在这里搜索也是如此。我很难过。我希望我失踪的并不简单。有什么帮助吗?

<section class="inner-pageBanner" style="width:100%; height:300px; 
background: url(/uploads/home.png) no-repeat center center; background-size:cover;">
&nbsp;
</section>
<div class="banner-text">
<h2 style="margin-top:100px; font-size:80px; color:#333;">Search 
Results</h2>
</div>
<section class="homeAnimation">
<div class="featured-products products-slider">
    <div class="container">

        <div class="col-md-12">

            <?php


                $seg2 = $this->uri->segment('2');
                $search = (empty($seg2) ? $_POST['search'] : $seg2);
                    $itemsq = $this->db->query("SELECT * from `products` where `text` like '%" . htmlspecialchars(addslashes($search)) . "%'");
                    $items = $itemsq->result();

                    foreach($items as $item){
                    ?>

                    <div class="col-md-6 featured-item">
                        <div class="col-md-12 featured-background">
                            <div class="col-md-4">
                                <a href="/product/<?php echo urlencode($item->code) . '/' . slugify($item->text); ?>"><img class="featured-img" src="<?php echo $item->image; ?>"/></a>
                            </div>
                            <div class="col-md-8">
                                <div class="row">
                                    <div class="col-md-12">
                                        <a class="featured-title"
                                           href="/product/<?php echo urlencode($item->code) . '/' . slugify($item->text); ?>">
                                            <h4><?php echo $item->text; ?></h4>
                                        </a>
                                        <p class="trunc-desc"><?php echo $item->text; ?></p>
                                    </div>
                                </div>
                                <div class="row " style="margin-top:0px; margin-bottom:0px;">
                                    <div class="col-md-12">
                                        <h4 style="margin-top:0px; font-size:18px;">As Low As: &nbsp; &nbsp;
                                            <span
                                                style="display: inline; color:forestgreen">$<?php echo number_format($item['price'] + ($item['price'] * ($settings->markup / 100))); ?></span>
                                        </h4>

                                        <br/><a
                                            href="/product/<?php echo urlencode($item->code) . '/' . slugify($item->text); ?>"
                                            class="featured-buy-btn">Buy Now</a>

                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php

                }

            ?>





        </div>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

此行代码中的

错误

<?php echo number_format($item['price'] + ($item['price'] * ($settings->markup / 100))); ?>

...

$item['price'] 

更改为

$item->price 

答案 1 :(得分:0)

或者您可以使用此函数db_result_to_array($îtems)将Mysql结果转换为关联数组。然后,您可以使用$item['key']访问数组的值。在关联数组中,键将是列标题。