Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter和数据库问题_Php_Codeigniter - Fatal编程技术网

Php Codeigniter和数据库问题

Php Codeigniter和数据库问题,php,codeigniter,Php,Codeigniter,对,我是新来的,有点不了解。好的,我正在尝试引入一些数据,我得到了一些错误,我有点困惑到底发生了什么 以下是型号代码: public function get_webstore_sets($limit, $offset) { $this->db->select("*"); $this->db->from('st_posts'); $this->db->where("type", "webstore");

对,我是新来的,有点不了解。好的,我正在尝试引入一些数据,我得到了一些错误,我有点困惑到底发生了什么

以下是型号代码:

 public function get_webstore_sets($limit, $offset) {
        $this->db->select("*");
        $this->db->from('st_posts');
        $this->db->where("type", "webstore");
        $this->db->limit($limit, $offset);
        $this->db->order_by('created', 'DESC');
        $query = $this->db->get();
        $data = $query->result_array();
        return$data;
    }

    public function count_webstore_sets() {
        $this->db->select("*");
        $this->db->from('st_posts');
        $this->db->where("type", "webstore");
        $this->db->order_by('created', 'DESC');
        $query = $this->db->get();
        $count = $query->num_rows();
        return $count;
    }
下面是我在控制器中尝试的内容:

class Webstore extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("post");
        $this->load->database();
        $this->load->helper("url");


    }
    public function index() {

        $this->data['posts'] = $this->post->get_webstore_sets($limit=null, $offset=null); // calling Post model method getPosts()
        $data = array('page_title' => 'Store', 'video_content');       
        $this->layout("pages/webstore", $data);
    }


}
然后将其引入HTML:

 <?php foreach ($posts as $webstore): ?>


            <div class="col-md-12" style="height: 225px;">
                <div class="col-md-3">
                    <?php
                    $webstore['images'] = explode(".", $webstore['images']);
                    ?>
                    <img class="thumbnail" width="250px" src="<?php echo $video['images'][1]; ?>.gif"/>
                </div>

                <div class="col-md-5">
                    <h3><?php echo $webstore['title']; ?></h3>
                </div>

                <div class="col-md-4 text-center">
                    Date Added: <?php echo date('d-m-y', strtotime($webstore['created'])) ?>
                     <hr>
                     <a href="http://clips4sale.com/64171/10768027" target="_blank" class="btn btn-primary center-block">Select or Exclusive to www.Borderlandbound.com<br> Please Visit Our Clips Store For <br>Many More Ultra-Hot Videos Like This</a>
<hr>
                </div>

            </div>

            <hr>
        <?php endforeach; ?>

我已删除了文件路径,以防万一;)针对上述错误进行了编辑

您正在调用的
get\u webstore\u set()
没有参数,因此请填写一些参数(限制、偏移)或按如下方式定义函数:

public function get_webstore_sets($limit=null, $offset=null) ...
我建议在此代码中,在类
Webstore

的函数
index()
中给出参数:

public function index()
{
    $this->data['posts'] = $this->post->get_webstore_sets($limit=null, $offset=null); // calling Post model method getPosts()
    $data = array('page_title' => 'Store', 'video_content');       
    $this->layout("pages/webstore", $data);
}
您正在传递要查看的
$data
数组,但不是
$this->data
数组。另外,
$data
数组的
'video\u content'
元素应该有它的关键,让您在视图中接近它。还是键本身缺少值

将其更改为:

public function index() {

    $this->data['posts'] = $this->post->get_webstore_sets($limit=null, $offset=null); // calling Post model method getPosts()
    $this->data['page_title'] = 'Store';
    $this->layout("pages/webstore", $this->data);
}

现在,您应该能够在视图文件中获取
$posts
变量。只需检查如何处理value/key“video_content”。

遇到PHP错误严重性:注意消息:未定义变量:webstore Filename:pages/webstore.PHP行号:39这意味着您试图使用一个未分配值的变量(名为“webstore”)。好的,我在哪里分配值?对不起,我是一个noob,他的php开发让他失望了!我非常感谢您提供的所有帮助,您需要编辑您的问题并显示使用$webstore的代码。与您的问题无关,但我看到您有此代码
$this->load->model(“post”)类Webstore的构造函数和
索引()方法中的code>。你只需要一次。如果您有其他使用该模型的方法,请将其保留在构造函数中。是的,现在将其从索引中删除,谢谢!太棒了,谢谢你,只需要弄清楚为什么它会显示一个空白屏幕,然后所有的事情都应该完成,但有一种感觉,这与HTML有关,谢谢你所有的帮助这行$this->db->where(“type”,“webstore”);选择列类型和类型值webstore??检查是否从DB获得任何有效结果。在模型方法的末尾,输入
var\u dump($data);退出这样,您将在该点停止进一步执行,并查看查询是否正确。
public function index() {

    $this->data['posts'] = $this->post->get_webstore_sets($limit=null, $offset=null); // calling Post model method getPosts()
    $this->data['page_title'] = 'Store';
    $this->layout("pages/webstore", $this->data);
}