0

I am new to Codeigniter.

my db controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Dbview extends CI_Controller{
        public function index()
        //standard SQL Query
        $sql = "SELECT * FROM 'news'",
        $data['query_sql'] = $this->db->query($sql);
        //active record query
        $data['query_ar'] = $this->db->get('news');
        //load view
        $this->load->view('dbview',$data);}
?>

my dbview in view

DB Test

<br />
<b>Standard SQL Query</b> <pre><?php print_r($query_sql->result_array()); ?>></pre>
<br />
<b>Active Record Query</b> <pre><?php print_r($query_ar->result_array()); ?></pre> 

I set up database in phpmyadmin, and put the database info into config/database when I try to open the browser http://localhost/WeatherFinder/index.php/dbview nothing is opening. whats wrong or what else I haven't done? Thx

J.J
  • 3
  • 3
  • if its a completely white screen, double check your database settings are correct, maybe post them here. – coderodour Feb 09 '17 at 20:09
  • Is your filename Dbview.php only first letter must be uppercase explained here https://www.codeigniter.com/user_guide/general/styleguide.html#file-naming and also you don't need to close controller https://www.codeigniter.com/user_guide/general/styleguide.html#php-closing-tag –  Feb 09 '17 at 20:22
  • @coderodour, Its not white, its 404 Page Not Found The page you requested was not found. – J.J Feb 09 '17 at 20:30
  • @wolfgang1983 I changed it to lowercase, still not working – J.J Feb 09 '17 at 20:36
  • also ensure apache rewrite module is enabled. You can accomplish this by issuing `sudo a2enmod rewrite` from command line in ubuntu. – coderodour Feb 09 '17 at 20:49
  • @coderodour my setting is $config['index_page'] = "index.php" , I just tried $config['index_page'] = "", still not working – J.J Feb 09 '17 at 20:51
  • @coderodour I am using MAMP – J.J Feb 09 '17 at 20:52
  • @coderodour have .htaccess at root RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] – J.J Feb 09 '17 at 20:53
  • @J.J I said upper case not lower case. –  Feb 09 '17 at 21:08
  • @wolfgang1983 oh sorry, my file name is Dbview.php. only the first letter is uppercase – J.J Feb 09 '17 at 21:51

2 Answers2

1

I think I may have found your issue. You are missing an opening curly brace for your index function, as pointed out and corrected in the code below.

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

  class Dbview extends CI_Controller{

    public function index(){ // --- This opening brace missing maybe the issue.

      //standard SQL Query
      $sql = "SELECT * FROM 'news'",
      $data['query_sql'] = $this->db->query($sql);

      //active record query
      $data['query_ar'] = $this->db->get('news');

      //load view
      $this->load->view('dbview',$data);
    }
}

You do not need to and are discouraged from closing your controllers with a ?>.

coderodour
  • 1,072
  • 8
  • 16
0

Thank you for everyone trying to help! I think that I may found the problem. Its is in my model file, I haven't wrote it properly. I will try to fix it later. and keep you posted!

J.J
  • 3
  • 3