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
#2

Code:
$list['result'] = $this->search_model->prtc_search($_POST['prtc_search']);
$list['searchquery']=$_POST['prtc_search'];
These two lines are line number 818 and 819 the warning messages points to
Reply
#3

(06-02-2015, 06:35 AM)karmad Wrote: You have problema     "if ($result==1)"  is array not int value, solution is:


Code:
$cant =count($result);
if ($cantt==1)
 
Reply
#4

(06-02-2015, 07:12 AM)PRichard Wrote:
(06-02-2015, 06:35 AM)karmad Wrote: You have problema     "if ($result==1)"  is array not int value, solution is:



Code:
$cant =count($result);
if ($cantt==1)
 @PRichard, did you mean to change the code in my view like this,
Code:
<?php

$cant= count($result);
        if ($cant==1)
        {
            echo "NO DATA FOUND";
        }
        else
        {?>
It still gives me the error message from line number 818 and 819. which is this lines
Code:
$list['result'] = $this->search_model->prtc_search($_POST['prtc_search']);

            $list['searchquery']=$_POST['prtc_search'];
One more thing I noticed, the query always shows all the data in my table irrespective of the search parameter is there in the database or not! what may be the problem? Thank you for the response as well
Reply




Theme © iAndrew 2016 - Forum software by © MyBB