从codeigniter中的index.php中的数据库中获取数据 [英] fetch data from database in index.php in codeigniter

查看:72
本文介绍了从codeigniter中的index.php中的数据库中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个博客,该博客与Codeigniter筹码工作中的现金返还有关.而且我有报价数据库.我想从数据库中获取所有报价到index.php(视图).这是我的默认设置. 问题是如何在index.php中获取数据. index.php是我网站的主页.

I have blog which is related to a cashback in codeigniter franework. and i have database of offers. i want to fetch all offers from database to index.php(view). this is my default. The problem is how to fetch data in index.php. index.php is my main page of my website.

我尝试过的

user.php(控制器)


    public function  testing()
    {
            $this->load->view('user/index.php');
            $this->load->model('showoffers');
            $offers = $this->showoffers->showoffersmodel();
            $this->load->view('showoffers',['offers'=>$offers]);
           
    }

showoffers.php (模型)

<?php

class showoffers extends CI_Model
{
    public function showoffersmodel()
    {
        $q = $this->db->select('*')
                    
                      ->from('offers')
                      ->get();
        return $q->result();
    }
}
?>

index.php (查看)



  <?php if(count($offers)): ?> 
  <?php foreach ($offers as $emp): ?>

                      <div  class="text-center">
                        <br>
                        <img  style="margin-left: -80%;" border="0" height="100" width="120" src="<?php echo base_url('image/amazon.png'); ?>" class="rounded" alt="...">
                        
                        <h2><?=  $emp->title; ?></h2>

                     <div class="row">
                       <div  class="col-sm-6">
                         
                       </div>
                       
                             <div class="col-sm-6 details">
                             <?=  $emp->details; ?>
                                 <br>
                                 <br>
                                 <a style="font-size: 15px;" href="<?=  $emp->link; ?>" class="badge badge-warning">Click Here to collect Cashback</a>
                                </div>
                             
                        </div>
                        <button type="button" class="btn btn-success btn78">
                        <i class="fa fa-check" aria-hidden="true"></i>
                              Verified 
                             
                              </button>
                      </div>   
                      
                      
<?php endforeach; ?>
<?php else: ?>
<?php endif; ?>

我遇到的错误

Unable to load the requested file: showoffers.php

请帮助!

推荐答案

控制器:

public function testing()
{
  $data['offers'] = $this->showoffers->showoffersmodel();
  $this->load->view('user/index', $data);
}

型号:

public function showoffersmodel()
{
  $query = $this->db->get('offers');
  return $query->result();
}

查看:

<?php if(count($offers)): ?> 
  <?php foreach ($offers as $emp): ?>

                      <div  class="text-center">
                        <br>
                        <img  style="margin-left: -80%;" border="0" height="100" width="120" src="<?php echo base_url('image/amazon.png'); ?>" class="rounded" alt="...">
                        
                        <h2><?=  $emp->title; ?></h2>

                     <div class="row">
                       <div  class="col-sm-6">
                         
                       </div>
                       
                             <div class="col-sm-6 details">
                             <?=  $emp->details; ?>
                                 <br>
                                 <br>
                                 <a style="font-size: 15px;" href="<?=  $emp->link; ?>" class="badge badge-warning">Click Here to collect Cashback</a>
                                </div>
                             
                        </div>
                        <button type="button" class="btn btn-success btn78">
                        <i class="fa fa-check" aria-hidden="true"></i>
                              Verified 
                             
                              </button>
                      </div>   
                      
                      
<?php endforeach; ?>
<?php endif; ?>

希望这会有所帮助!

这篇关于从codeigniter中的index.php中的数据库中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆