Welcome Guest, Not a member yet? Register   Sign In
help with query
#1

[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');
?>
#2

[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');
#3

[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;




Theme © iAndrew 2016 - Forum software by © MyBB