php - 无法获取mysql数据(CodeIgniter选择)

标签 php mysql codeigniter

我无法通过选择“请帮助我找出错误”来将 mysql 数据加载到 View 中。谢谢。

查看

<div class="grid">
<div class="row">
    <?php $this->load->view('admin/admin_topmenu.php'); ?>
</div>
<div class="row">
    <div class="span10 box" style="padding: 10px;">


        <p>Recent Messages</p>
        <table class="table hovered">
            <thead>
            <tr class="selected">
                <th class="text-left">Name</th>
                <th class="text-left">Email</th>
                <th class="text-left">Phone</th>
                <th class="text-left">Message</th>
            </tr>
            </thead>
            <tbody>
            <?php echo form_open('admin_forms/inbox')  ?><!-- start of the form -->
            <?php if(isset($records)) : foreach($records as $row) : ?>
            <tr>
                <td class="right"><?php echo $row->contactus_name; ?></td>
                <td class="right"><?php echo $row->contactus_email; ?></td>
                <td class="right"><?php echo $row->contactus_phone; ?></td>
                <td class="right tertiary-text-secondary text-justify"><?php echo $row->contactus_comment; ?></td>

            </tr>
            <?php endforeach; ?>
            <?php endif; ?>
            <?php echo form_close(); ?><!-- END of the form -->
            </tbody>
            <tfoot></tfoot>
        </table>
    </div>

    <div class="span3">
        <nav class="sidebar light">
            <ul>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Inbox <strong>(5)</strong>
                    </a>
                </li>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Send
                    </a>
                </li>
                <li>
                    <a href="#">
                        <i class="icon-home"></i>
                        Newsletter/Ad
                    </a>
                </li>
            </ul>
        </nav>
    </div>
</div>

Controller

 <?php class Admin extends CI_Controller {
function index()
{

}
function inbox()
{
    $data = array();
    if($query = $this->mod_contactus->get_records())
    {
        $data['records'] = $query;
    }
    $this->load->view('admin/admin_messages',$data);
}

}

型号

<?php 
class Mod_contactus extends CI_Model
{

    function get_records()
    {
        $query = $this->db->get('tbl_contactus');
        return $query->result();
    }


    function add_record($data)
    {
        $this->db->insert('tbl_contactus', $data);
        return;
    }


    function update_record()
    {
    }

}

当我转到页面的源代码时,单击表单发布方法,它给出了 404 页面未找到错误。

最佳答案

我假设您能够访问该页面,并且在提交表单时收到错误消息。除非您在 application/config/routes.php 文件中设置了特殊的路由,否则我相信可以通过在 View 中更改此行

<?php echo form_open('admin_forms/inbox')  ?><!-- start of the form -->

<?php echo form_open('admin/inbox')  ?><!-- start of the form -->

就可以了。

我这么说是因为您的 Controller 的名称是 Admin 并且为了调用它(默认情况下),您必须在 URL 中使用 admin 而不是 admin_forms

关于php - 无法获取mysql数据(CodeIgniter选择),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23531777/

相关文章:

php - 在 phpmyadmin 中导出数据库失败(本地主机)

php - MySQL 与 Readdir PHP

php - 如何根据所选类别向表单添加额外字段?

mysql - 如何获得每天最多 5 天的总计数值

php - 编写准备好的语句以从表中检索数据( fatal error )

php - 代码点火器/数据映射器 : Two one-to-many relationships to the same table not working

php - PHP 如何使用比较运算符比较字符串?

mysql - 将另一个表中的计数添加到现有查询

javascript - Ajax请求总是出错

mysql - CodeIgniter、事件记录、JOIN 有帮助吗?