0

Error : A PHP Error was encountered Severity: Notice

Message: Undefined variable: records

Filename: views/Search_data.php

Line Number: 80

Backtrace:

File: /home/paychzaq/public_html/application/views/Search_data.php Line: 80 Function: _error_handler

File: /home/paychzaq/public_html/application/controllers/Search.php Line: 13 Function: view

File: /home/paychzaq/public_html/index.php Line: 315 Function: require_once

Controller :

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Search extends CI_Controller {
    function __construct() {
    parent::__construct();
     $this->load->model('Search_model'); 
     $this->load->database();
     $this->load->library('session');
 }

function index(){
$this->load->view('Search_data');
}

public function searchUser() {

        $key = $this->input->post('search');

        if(isset($key) and !empty($key)){
            $data['records'] = $this->Search_model->searchRecord($key);
            $data['link'] = '';
            $data['message'] = 'Search Results';
            $this->load->view('Search_data' , $data);
        }
        else {
            redirect('Search') ;
        }
    }
}
?>

Model :

<?php
class Search_model extends CI_Model 
{
    public function searchRecord($key)
    {
        $this->db->select('*');
        $this->db->from('campaigns');
        $this->db->like('title',$key);
        $this->db->or_like('category',$key);
        $this->db->or_like('description',$key);
        $query = $this->db->get();

          if($query->num_rows()>0){
          return $query->result();
        }
    }
}
?>

View :

<?php
  foreach($records as $row)
  {
  $sr=$row->photo;
$ur=   site_url()."/campaign_info/campaign_detail/".$row->campaignid."/".$row->title."";

?>
           <div class="col-lg-3 col-sm-6">
            <div style="height: 40rem;" class="card card-product">
              <div class="card-header border-0">
                <h2 class="h6">
                  <a href="#"><?php echo $row->title?></a>
                </h2>
              </div>
              <!-- Product image -->
              <figure class="figure">
               <a href="<?php echo $ur; ?>"> <img alt="Image placeholder" src='<?php echo $sr; ?>' style="max-width: 100%; height: auto; object-fit: contain;" class="img-center img-fluid"></a>
              </figure>
              <div class="card-body">
                <!-- Price -->
                <div class="d-flex align-items-center mt-4">
                  <span class="h6 mb-0"> <?php echo $row->price?> RS</span>
                  <span class="badge badge-success rounded-pill ml-auto"><a style="color: white"href="<?php echo $ur;?>">Details</a></span>

                </div>
              </div>
              <div class="p-4 border-top">
                <div class="row">
                  <div class="col-6 text-center">
                    <a href="<?php echo "#abc".$row->campaignid;?>" class="btn btn-sm btn-white btn-icon-only rounded-circle ml-4" data-toggle="modal">
                <span class="btn-inner--icon"><i class="fas fa-paper-plane"></i></span>
            </a>
                    <span class="d-block text-sm">Send Proposal</span>
                  </div>
                  <div class="col-6 text-center">
                    <span class="h5 mb-0"><?php echo $row->deadline ?></span><sup></sup>
                    <span class="d-block text-sm">Deadline</span>
                  </div>
                </div>
              </div>

<?php
   $url='proposal/validation/'.$row->campaignid;
  ?>
            <div class="modal fade" id="<?php echo "abc".$row->campaignid;?>" tabindex="-1" role="dialog" aria-hidden="true">
          <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
              <div class="modal-body"> 
              <?php echo form_open($url)?>
               <div class="form-group">
                  <label class="form-control-label">
                    Your Fees
                  </label>
                  <input name="fee" type="text" class="form-control">
                </div>
                <div class="form-group">
                  <label class="form-control-label">
                    Days To Complete
                  </label>
                  <input  name="days" type="text" class="form-control">
                </div>
                <!-- Project description -->
                <div class="form-group">
                  <label class="form-control-label mb-0">
                    Details 
                  </label>
                  <small class="form-text text-muted mb-2 mt-0">
                    This textarea will autosize while you type
                  </small>
                  <textarea name="details"class="form-control" data-toggle="autosize" rows="2"></textarea>
                </div>
                <button type="submit" class="btn btn-sm btn-primary rounded-pill mr-auto">Send</button>
               <?php echo form_close()?>
              </div>

            </div>
          </div>
        </div>
              <div class="card-footer">
                <div class="actions d-flex justify-content-between">
                  <a href="#" class="action-item">
                    <i class="fas fa-star"></i>
                  </a>
                  <a href="#" class="action-item">
                    <i class="fas fa-chart-pie"></i>
                  </a>
                  <a href="#" class="action-item text-danger">
                    <i class="fas fa-trash-alt"></i>
                  </a>
                </div>
              </div>
            </div>
</div>


    <?php
    }
       ?>
3
  • 1
    foreach($records as $row) Where does $records get defined? It is not in your code. Commented Apr 6, 2020 at 12:35
  • describe a little more your problem, please Commented Apr 6, 2020 at 12:39
  • records are defined in controller : $data['records'] = $this->Search_model->searchRecord($key); Commented Apr 6, 2020 at 12:42

2 Answers 2

1

I think it's undefined because on your index method you haven't declare the $records variable yet. On your view, try to filter if $records is available like this :

<?php
if (!empty($records)) {
  foreach($records as $row)
  {
  ...
Sign up to request clarification or add additional context in comments.

Comments

0

In the model

if($query->num_rows()>0){
   return $query->result();
}else{
   return array();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.