![]() |
Need help with writing a query!!! - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Need help with writing a query!!! (/showthread.php?tid=33376) |
Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]heylarson[/eluser] Suppose I have a mysql table called 'events' that looks as such. Code: id start_date title The URL references the events by their event id as such, http://foo.com/event/2. I would like to put a prev and next event links, on the current event the user is looking at. Obviously, the prev/next event links would point to the nearest events based off their 'start_date' and referenced by their 'id'. For example, if you're looking at, http://foo.com/event/1, the prev link would be, http://foo.com/event/4, and the next link would be, http://foo.com/event/3. I have tried sorting the events by 'start_date' and return the results as an array, but I can't seem to get the surrounding event id's for the currently viewed event. Any help would be REALLY appreciated!! Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]Bart v B[/eluser] Something like this? Code: $sql = "SELECT * FROM events ORDER BY start_date ASC"; A date or datime in SQL is written like this: 2010-01-01 So i guess that your using a VARCHAR field, and there you can not doing things with. I think you can make it better a DATE or a DATETIMe column for that. :-) Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]heylarson[/eluser] I currently have: Code: //get the details for a particular event based off the event id Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]Bart v B[/eluser] [quote author="heylarson" date="1282698566"]I currently have: Code: //get the details for a particular event based off the event id Is this a good start to look? Pagination Class Then it should be something like this: Code: function GetEventView() in your Conroller: Code: $data['pagination'] = $this->pagination->create_links(); And everything goes atomatic ;-) Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]heylarson[/eluser] I appreciate the feedback, but I think i'm looking more along the lines of how to take the results from a query and access individual values like an array. For example, I have the following function: Code: function GetEventView($id) The results are: Code: Array If someone is looking at event id 1 (which is position 2 in the array), I want to be able to store the next event in the array, which is event id 4 (position 3 in the array), and store the id (which is 4) into a variable, let's call it $next. Don't get hung up on the format of the date, i've abbreviated much of this code to just give the gist of what i'm looking for. Need help with writing a query!!! - El Forum - 08-24-2010 [eluser]heylarson[/eluser] Alright, so after my racking my brain, I figured it out: Code: function GetEventView($id) |