Welcome Guest, Not a member yet? Register   Sign In
Noob Help Please!
#1

[eluser]draconus[/eluser]
I am trying to create a dynamic site as my first CI project, and I have already loaded the site table in my database up with all the data it needs to accomplish this task. here are the columns:
id, page, title, body, section

The page field is what i am using as the search term, since it will then display the page name in the url. The title is self explanatory and the body contains the body code. The section is the key that links this table to the sidebar table and loads the sidebar based upon section.

I created a model, a controller, and a view for this, but i cannot seems to get the query to run properly at all, since it seems to get stuck on it's way to the controller! The view just has echo tags for title, body, etc. so as simple as this is, I should have no issues outputting it if i get it to the controller. The data is being output to the following url:
/page/ (I did the whole no index page thingy, which works nicely)

My Model(Site.php):
Code:
<?
class Site extends Model {
    var $page = 'Index';
    var $title = '';
    var $body = '';
    var $section = '';

    function Site(){
        parent::Model();
    }

    function insert_entry(){
        $this->page   = $_POST['page'];
        $this->title = $_POST['title'];
        $this->body = $_POST['body'];
        $this->section = $_POST['section'];
        
        $this->db->insert('site', $this);
    }

    function update_entry(){
        $this->page   = $_POST['page'];
        $this->title = $_POST['title'];
        $this->body = $_POST['body'];
        $this->section = $_POST['section'];

        $this->db->update('site', $this, array('id' => $_POST['id']));
    }
    
    function display($page){
        $this->db->select('*')->from('site')->where('page', $page)->limit(10, 20);
        $query = $this->db->get();
    }
}
?>

And my Controller(page.php):
Code:
<?

class Page extends Controller {
    
    function index(){
        $this->load->model('Site');
        $data['query'] = $this->Site->display("index");
        $this->load->view('page', $data);
    }
}
?>
#2

[eluser]Randy Casburn[/eluser]
This looks like a terrific start. Why don't we try it with raw SQL and see what happens and then back into the CI syntax?

Try replacing:

Code:
$this->db->select('*')->from('site')->where('page', $page)->limit(10, 20);

with

Code:
//$this->db->select('*')->from('site')->where('page', $page)->limit(10, 20);
$sql = "SELECT * FROM site WHERE page='$page' LIMIT 10, 20";
$query = $this->db->query($sql);

and see what happens.

[EDIT] Note the correction to the code. I added the $query = above (whoopsy)

Randy
#3

[eluser]draconus[/eluser]
So far so good, this is a much better start. Here is what the view is showing:


A Database Error Occurred

Error Number: 1096

No tables used

SELECT *
#4

[eluser]Pascal Kriete[/eluser]
I don't think it's active record. You're not returning a result to the controller.
Code:
$query = $this->db->get();
// Add this
return $query;

// Or better
return ($query->num_rows() > 0) ? $query->result() : FALSE;

[Edit: Welcome to CodeIgniter, draconus.]
#5

[eluser]Randy Casburn[/eluser]
Echo $sql. Somehow it's getting mangled. Let's take a look.
#6

[eluser]draconus[/eluser]
Adding the return line still gives the same result.
echo returns the following:

SELECT * FROM site WHERE page='index'

Which is correct. Wierd huh? It seems that everything after the asterisk dies. And i even did the adding of the asterisk into the db.php

No, i replaced the asterisk with body, but still the same error
#7

[eluser]Randy Casburn[/eluser]
Inparo is correct, you have no return statement in your display() method.

Never even saw it!

Thanks Inparo
#8

[eluser]draconus[/eluser]
Code:
function display($page){
        // $this->db->select('*')->from('site')->where('page', $page);
        $sql = "SELECT * FROM site WHERE page='$page'";
        // Echo $sql;
        $this->db->query($sql);
        $query = $this->db->get();
        return ($query->num_rows() > 0) ? $query->result() : FALSE;
    }

gives the same error
#9

[eluser]Randy Casburn[/eluser]
Are you using 1.7.0?
#10

[eluser]draconus[/eluser]
yes




Theme © iAndrew 2016 - Forum software by © MyBB