title: 500 Internal Server Error and undefined variable error in codeigniter in foreach loop?
body: <p>I searched a lot in google but didn't find any solution for my problem.its a last hope to get solution. I remove index.php from url with htaccess.
  My htaccess is:</p>
  
  <pre><code>RewriteEngine on
  RewriteCond $1 !^(index\.php|public|\.txt) 
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?$1
  </code></pre>
  
  <p>my problem is in my entire codeigniter project in any view if i think to fetch data from database it gives me error of undefined variable. In chrome debugger it shows <code>500 Internal Server Error</code>.
  Variable that i am using for fetching data shows this variable is undefined and also shows 505 internal error.I am sharing my mvc code.please review my code i am using version 3. </p>
  
  <p>Model:</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Pay_slips extends CI_Model{
  
  function __construct()  
        {       
          parent::__construct();  
        } 
  
  
        function select() {
          $query = $this-&gt;db-&gt;query('SELECT * FROM india_salary_slip_details');
           return $query;
          } 
  
  }
  </code></pre>
  
  <p>Controller :</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Pay_slips extends CI_Controller {
  
      function __construct() {
          parent::__construct();        
          $this-&gt;load-&gt;model('pay_slips');
      }
  
  
  
      public function index()  
        {  
           //load the database  
           $this-&gt;load-&gt;database();  
           //load the model  
           $this-&gt;load-&gt;model('select');  
           //load the method of model  
           $data['h']=$this-&gt;select-&gt;select();  
           //return the data in view  
           $this-&gt;load-&gt;view('responsibilities/pay_slips', $data);  
        }   
  
  
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>   &lt;?php  
       foreach ($h-&gt;result() as $row)
         {  
          ?&gt;&lt;tr&gt;  
             &lt;td&gt;&lt;?php echo $row-&gt;PAY_MONTH;?&gt;&lt;/td&gt;  
             &lt;td&gt;&lt;?php echo $row-&gt;PAY_YEAR;?&gt;&lt;/td&gt;  
            &lt;/tr&gt;  
        &lt;?php }  ?&gt; 
  </code></pre>
  
  <p>image with errors:
  <a href="https://i.stack.imgur.com/cw4rw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cw4rw.png" alt="enter image description here"></a></p>
  
  <p>I have data in database.Eveything is fine but still dont know why this happens.</p>