无法获取mysql数据(CodeIgniter选择) [英] Can't get mysql data (CodeIgniter Selecting)

查看:87
本文介绍了无法获取mysql数据(CodeIgniter选择)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法加载mysql数据到视图通过选择请帮助我找出错误。谢谢。



查看

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


< p>最近的讯息< / p>
< table class =table hovered>
< thead>
< tr class =selected>
< th class =text-left> Name< / th>
< th class =text-left>电子邮件< / th>
< th class =text-left>电话< / th>
< th class =text-left> Message< / th>
< / tr>
< / thead>
< tbody>
<?php echo form_open('admin_forms / inbox')?><! - 表单开始 - >
<?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 - >
< / 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>
发送
< / a>
< / li>
< li>
< a href =#>
< i class =icon-home>< / i>
Newsletter / Ad
< / a>
< / li>
< / ul>
< / nav>
< / div>
< / div>



b
$ b

 <?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 文件中有特殊的路由设置,我相信在你的视图中改变这一行

 <?php echo form_open('admin_forms / inbox')?><! - 表单开始 - > 

 <?php echo form_open('admin / inbox')?><! - 表单的开头 - > 



我说这是因为你的控制器名称是 Admin ,为了调用它在网址中使用 admin ,而不是 admin_forms


I can't load mysql data to the view by selecting please help me to find out the error. thank you.

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);
}

}

model

<?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()
    {
    }

}

When I go to the Source Code of the page click the form post method it gives me 404 Page Not Found error.

解决方案

I'm assuming you are able to get to the page and you are getting the error upon form submission. Unless you have special routes setup in your application/config/routes.php file I believe by changing this line in your view

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

to

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

would do the trick.

I say this because your controller's name is Admin and in order to call it (by default) you would have to use admin in the URL and not admin_forms.

这篇关于无法获取mysql数据(CodeIgniter选择)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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