dongrenzheng1619 2016-02-17 13:33
浏览 30
已采纳

codeigniter不能使用stdclass类型的对象作为数组

i need to view products from the database each products have their own category this error pops up to my view when i try to view. what i am doing wrong in this one ?

my view:

<?php
            foreach ($products as $alls) {
                $id = $alls['product_id'];
                $name = $alls['product_name'];
                $description = $alls['product_description'];
                $price = $alls['product_price'];
                $picture = $alls['img_name'] . $alls['ext'];
                ?>

                <div class="col-md-4"><a data-toggle="modal" data-target="#myModal">
                        <img class = "bread_img" id = "bread_img_<?php echo $id;?>" src="<?php echo base_url() . 'assets/' . $picture; ?>"  onMouseOut="this.src = '<?php echo base_url() . 'assets/' . $picture; ?>'" width="230" height="192"></a>
                        <input type ="hidden" id = "hidden_name_<?php echo $id;?>" value = "<?php echo $name;?>" >
                        <input type ="hidden" id = "hidden_desc_<?php echo $id;?>" value = "<?php echo $description;?>" >
                    <br><br> <h5 class="names" id="pname" src="<?php echo $name; ?>"><?php echo $name; ?></h5>₱&nbsp;<?php echo $price; ?>
                    <br><br><br><br><br>
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-l">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h4 class="modal-title" id="myModalLabel"> <?php echo $name; ?></h4>
                                </div>
                                <div class="modal-body">
                                    <img  src="<?php echo base_url() . 'assets/' . $picture; ?>" width="500" height="417" id = "modal_img">
                                    <br><br><h6 class="modal-title" id="myModalLabels"> <?php echo $description; ?></h6><br><br>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            <?php } ?>   

controller:

public function view_products() {

            $id = $this->uri->segment(3);
            $data['products'] = $this->user->viewprod($id);
            $this->load->view('product_viewpage', $data);

    }

model:

  public function viewprod($id) {
          $query = $this->db->query("SELECT * from product_table WHERE product_category = '$id'");
        $r = $query->result();
        return $r;

    } 
  • 写回答

3条回答 默认 最新

  • douwuli4512 2016-02-17 19:23
    关注

    In your model you are using result() function and this will return you result in object form.

    $query->result();
    

    Solution 1:

    If you still want to use result() function than you need to change your view as:

    $id = $alls->product_id; 
    $name = $alls->product_name; $description = $alls->product_description; 
    $price = $alls->product_price; 
    $picture = $alls->img_name. $alls->ext;
    

    Solution 2:

    If you don't want to change your view file than you must need to use result_array() in your model as:

    $query->result_array(); // will return you result in array format.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法