CodeIgniter Forums

Full Version: help with query
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]dadamssg[/eluser]
how do i get his to work.

I copied and pasted my query from my non-codeigniter page to try to use in codeigniter but its thinking that Surrounding is a column in my db but it isn't.

i don't know what to put around Surrounding to tell codeigniter that i want to pull up all events which are not Surrounding.

This should be pretty simple, just don't know the proper syntax...
Code:
<?php
$data['query'] = $this->db->query('SELECT * FROM test WHERE end >= NOW() AND event != 'Surrounding' ORDER BY start ASC');
?>

El Forum

[eluser]danmontgomery[/eluser]
You just need to fix your quotes.

Code:
$data['query'] = $this->db->query('SELECT * FROM test WHERE end >= NOW() AND event != "Surrounding" ORDER BY start ASC');

El Forum

[eluser]dadamssg[/eluser]
sweet well thats working now...maybe you can help me with putting it all work. I'm tryin to use a model that i just created. its not allowing me to use num_rows() on $query. It doesn't recognize it as an object. I don't know what im doing wrong

heres my controller
Code:
<?php

class Mains extends Controller {

    function Mains()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        
    }

    function index()
    {
        $data['title'] = "Home";
        $data['heading'] = "All Events";
        $this->load->model('Frontmodel');
        $this->Frontmodel->get_all_events();
        
        $this->load->view('main_view', $data);
    }
    
    
}

?>
heres my model
Code:
<?php

class Frontmodel extends Model {

    function Frontmodel()
    {
        parent::Model();
    }
    
    function get_all_events()
    {
        $data['query'] = $this->db->query("SELECT * FROM test WHERE end >= NOW() AND event != 'Surrounding' ORDER BY start ASC");
        return $data['query'];
    }



}

?>
and my view
Code:
<?php
session_start();
include("header_view.php");
head();
?>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1>&lt;?php echo $heading; ?&gt;</h1>

<hr>

&lt;?php if($query->num_rows() > 0): ?&gt;

&lt;?php foreach($query->result() as $row): ?&gt;

    <h3>&lt;?php echo stripslashes($row->title); ?&gt;</h3>
    &lt;?php echo date('l M j, Y    g:i a',strtotime($row->start)); ?&gt;
    <p>&lt;?php
        echo stripslashes($row->description);
        echo "<h4>By ".$row->createdby."</h4>";
        ?&gt;</p>

    <hr>
    &lt;?php endforeach; ?&gt;
&lt;?php endif; ?&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;