0
votes

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.

2

2 Answers

0
votes

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.

0
votes

You need to fetch the results,

So the line:

Actually, your variable $records is a resource, not a result set.

<?php if(isset($records)) : foreach($records as $row) : ?>

So, please use this resource and then fetch the records.

It should become:

<?php if(isset($records)) : foreach($records->result as $row) : ?>

<?php if(isset($records)) : foreach($records->result() as $row) : ?>