Welcome Guest, Not a member yet? Register   Sign In
How to solve this php error(Object of class CI_DB_mysql_result could not be converted
#1

(This post was last modified: 06-02-2015, 06:37 AM by karmad. Edit Reason: added some more codes )

I am developing an application on Codeigniter and trying to implement a search function from my database tables. The search query is working fine, I get the results as expected but the page adds up the following three errors. I am stuck with these 3 errors/warnings
Code:
1.(A PHP Error was encountered
Severity: Notice
Message: Undefined index: prtc_search
Filename: controllers/form.php
Line Number: 818)

2.(A PHP Error was encountered
Severity: Notice
Message: Undefined index: prtc_search
Filename: controllers/form.php
Line Number: 818)

3.(A PHP Error was encountered
Severity: Notice
Message: Object of class CI_DB_mysql_result could not be converted to int
Filename: views/prtc_search.php
Line Number: 2)

I am using the same codes to search data from other database tables and it works fine with no errors or warnings, but the same code is not working when it comes to this particular page. I am stuck on this will be grateful if someone could kindly give me clues or solutions on this. Below is the codes for the search page.
Code:
//view.php
<?php
        if ($result==1)
        {
            echo "NO DATA FOUND";
        }
        else
        {?>
    <div class="table">
        <div class="table_header">Edit from the following List of PRTC</div>
        <table >
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Country</th>
                <th>Dzongkhag</th>
                <th>Geog</th>
                <th>Village</th>
                <th>Address</th>                
                <th style="color:#FF2525;width:4%;">Edit</th>
            </tr>
        <?php  

                        $i=0;
            foreach($result as $row)
            {
                ?>
                <tr <?php /*if($i%2==0) echo 'style="background-color:#F2DEDE";'; else echo 'style="background-color:#D9EDF7";'; $i++;*/?>>
                    <td style="vertical-align:middle;"><?php echo $row['id']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['name']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['country']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['dzongkhag']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['geog']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['village']; ?></td>
                    <td style="vertical-align:middle;"><?php echo $row['address']; ?></td>                  
                    <td style="ertical-align:middle;">
                    <a href = "<?php echo base_url().'form/prtc_one/'.$row['id']; ?>">
                    <img src="<?php echo base_url();?>images/edit.png" title="Edit"></a>
                    </td>
                </tr>
                <?php
            }
        }
        ?>

        </table>
        </div>
    </div>
<!-- <a style="margin-left:2%;margin-top:20%;" href="<?php echo site_url('form/search_expo/'.$searchquery);?>">Export This..<img style="margin:0 !important;" src="<?php echo site_url('images/b_export.png')?>"></a> -->
Code:
//controller
    function prtc_search()
    {
        $session_user=$this->session->userdata('logged_in');
        if($session_user['ath']=='admin')
        {

            $list['result'] = $this->search_model->prtc_search($_POST['prtc_search']);
            $list['searchquery']=$_POST['prtc_search'];

            $data['session_user']    = $this->session->userdata('logged_in');
            $datah['title']         = "Sasec | PRTC Search"; //For Title
                    
                    $this->load->view('includes/header',$datah);
                    $this->load->view('includes/leftmenu',$data);
                    $this->load->view('includes/flag',$data);
                
                    $this->load->view('prtc_search',$list);

                    $this->load->view('includes/footer');
        }
        else{
            echo ' <script type="text/javascript">
                        alert("Access Error....");
                        </script>';
                redirect('login/home');
            }

    }
Code:
//model
    function get_prtc_one($id)
        {
            $query=$this->db->get_where('prtc_info',array('id' => $id));
            $query=$query->row_array();
            return $query;
Example of database query by the search function in search model
Code:
function prtc_search($searchquery)
    {
        $count = 0;

        //Search using id
        $this->db->select('*');
        $this->db->order_by('name ASC');
        $this->db->where("id LIKE '%$searchquery%'");
        $result = $this->db->get('prtc_info');
        if ($result->num_rows() > 0)
        {
            $row = $result->result_array();
            $count = 1;
            return $row;
        }
        

        //Search using name
        $this->db->select('*');
        $this->db->order_by('name ASC');
        $this->db->where("name LIKE '%$searchquery%'");
        $result = $this->db->get('prtc_info');
        if ($result->num_rows() > 0)
        {
            $row = $result->result_array();
            $count = 1;
            return $row;
        }

Your advice/solutions will be greatly appreciated.
Thank you
Reply


Messages In This Thread
How to solve this php error(Object of class CI_DB_mysql_result could not be converted - by karmad - 06-02-2015, 06:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB