Note that there are some explanatory texts on larger screens.

plurals
  1. POShow results grouped by value with codeigniter
    primarykey
    data
    text
    <p><strong>Problem 1:</strong></p> <p>Looking to display some events GROUPED as follows:</p> <p>Year<br> Month<br> event details here</p> <p>The database has the following structure:</p> <pre><code> event_year | event_month | event_day | event_name | event_description 2013 | 11 | 08 | Name 1 | Desc 1 2013 | 12 | 31 | Name 2 | Desc 2 2014 | 02 | 14 | Name 3 | Desc 2 2014 | 03 | 25 | Name 4 | Desc 4 </code></pre> <p>I would like it to display as follows:</p> <pre><code> 2013 November 08/11/2013 - Name 1: Desc 1 December 31/12/2013 - Name 2: Desc 2 2014 February 14/02/2014 - Name 3: Desc 3 March 25/03/2014 - Name 4: Desc 4 </code></pre> <p><strong>Problem 2:</strong></p> <p>There are also past events on the table, and of course we only want to display upcoming events. How would I solve that issue? As of now, I managed to display all events, which works quite well, and I also figured how to sort them by year and months, but it only gives me a list of all events, but not grouped. </p> <p>Here is the code out of the model:</p> <pre><code> function getEvents($limit = 20, $offset = 0) { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('events_posts'); $this-&gt;db-&gt;limit($limit, $offset); $this-&gt;db-&gt;order_by('event_year', 'desc'); $b = $this-&gt;db-&gt;get()-&gt;result(); return $b; } function getAllEvents() { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('events_posts'); $b = $this-&gt;db-&gt;get(); return $b; } </code></pre> <p>Here is the controller:</p> <pre><code> $events = $this-&gt;events_model-&gt;getEvents($config['per_page'], $from); $this-&gt;outputData['events'] = $events; $this-&gt;load-&gt;view('events/index',$this-&gt;outputData); </code></pre> <p>and my views page:</p> <pre><code> &lt;?php foreach($events as $event) { ?&gt; &lt;a href="&lt;?php echo site_url('events/view/' . $event-&gt;id); ?&gt;"&gt;&lt;h2&gt;&lt;b&gt;&lt;?php echo $this-&gt;lang-&gt;line('Event:'); ?&gt; &lt;?php echo $event-&gt;title ?&gt;&lt;/b&gt;&lt;/h2&gt;&lt;/a&gt; &lt;?php echo $event-&gt;descriptions ?&gt; &lt;?php echo $event-&gt;event_day ?&gt;/&lt;?php echo $event-&gt;event_month ?&gt;/&lt;?php echo $event-&gt;event_year ?&gt; a las &lt;?php echo $event-&gt;event_hour ?&gt;:&lt;?php echo $event-&gt;event_min ?&gt; horas &lt;?php } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload