Welcome Guest, Not a member yet? Register   Sign In
only pull one row from db to display problem

Im just trying to display one row of information on a page and i keep getting a 404.

I'm using an 'events' controller and im trying to pull the second segment of the uri as the event id number to query.

heres my event controller
class Events extends Controller {

    function Events()

    function index($id = null)
        //load models
    $newdata = array(
                   'page'  => 'mains',
        $data['title'] = "Home";
        $data['heading'] = "All Events";
        $page = $this->uri->segment(2);
        if (isset($page) && is_numeric($page))
              $page = $page;
              $page = 867;
        $data['query'] = $this->Eventmodel->get_event($page);
        $this->load->view('header_view', $data);
        $this->load->view('event_view', $data);

and heres my view

    <?php foreach($query->result() as $row): ?>

    <h3>&lt;?php echo clean_up($row->title); ?&gt;</h3>
    &lt;?php echo easy_date($row->start); ?&gt; -
    &lt;?php echo easy_date($row->end); ?&gt;
       &lt;?php echo clean_up($row->description); ?&gt;
       <h5>&lt;?php echo "By ".$row->createdby; ?&gt;</h5>

    &lt;?php endforeach; ?&gt;

i think i need to change that foreach thing because im only dealing with one row

my head_view just opens up the html
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
&lt;html &gt;
&lt;link rel='stylesheet' type='text/css' href='silk.css' /&gt;
&lt;title&gt; &lt;?=$title?&gt; &lt;/title&gt;
<li>&lt;?=anchor('mains', 'Home')?&gt;</li>
<li>&lt;?=anchor('mains/sports', 'Sports')?&gt;</li>
<li>&lt;?=anchor('mains/performance', 'Performance')?&gt;</li>
<li>&lt;?=anchor('mains/organization', 'Organization')?&gt;</li>
<li>&lt;?=anchor('mains/random', 'Random')?&gt;</li>

oh and heres the model im using

class Eventmodel extends Model {

    function Eventmodel()
    function get_event($num)
     $query = $this->db->query("SELECT * FROM test WHERE eventid = '$num'");        
     return $query;    
     function get_exists($eventid)    
    $query = $this->db->query("SELECT * FROM test WHERE end >= NOW() AND eventid = '$eventid'");
    $numrows = $query->num_rows();
    return $numrows;

[eluser]Craig A Rodway[/eluser]
If you read the documentation, you will see there is a function for returning one row - look for row().

well now ive learned that its not that. Its that i can't get the uri segment. For whatever reason i just can not assign the 3rd uri to anything. the uri im trying to capture is the number like below


im trying to use to get it but won't work
$id = $this->uri->segment(2);
        if (isset($id) && is_numeric($id))
              $page = $id;
              $page = 867;

and i know i have an event with an id of 867 so thats why i used that number. When i go to mysite.com/events/ it pulls up that event like its suppose to but if i try to add a third segment with another event id, say 868(which is also in the db), it pulls up a 404

*i mean 2nd segment

[eluser]Craig A Rodway[/eluser]
In that case, you should read the page about URLs in the user guide.

Quote:The first segment represents the controller class that should be invoked.
The second segment represents the class function, or method, that should be called.
The third, and any additional segments, represent the ID and any variables that will be passed to the controller.

From your example, mysite.com/events will call the index function of the event controller - which will work OK. But when you try to go to mysite.com/events/868, it will not work because the 868 function doesn't exist in the events class.

You have two options - make the URL include index mysite.com/events/index/868; or add a manual route like this using Routing.

$route['events/(:num)'] = 'events/index/$1';

awesome, THANK YOU. its working now and i understand that now.

Theme © iAndrew 2016 - Forum software by © MyBB