Welcome Guest, Not a member yet? Register   Sign In
Craigslist style orderby Date
#1

[eluser]mikeyhell[/eluser]
Hi All, I'm stuck on a problem and was looking for some insight. I know the solution is simple, but I can't seem to get this working. I'm returning the following to my view:

Code:
function get_all()
    {
        $this->db->select_max('postdate');
        //$this->db->distinct('postdate');
        $this->db->group_by('postdate', 'desc');
        $query = $this->db->get('events');

        if( $query->num_rows() > 0 ):
            
        $result = $query->result_array();
        
            foreach($result as $date ):
            
                $select_date = $date['postdate'];
                $this->db->where('postdate', $select_date);
                $query = $this->db->get('events');
                
                $return= $query->result();
                
            endforeach;
        
            return $return;
                
        else:

            return false;

        endif;

    }

But I am trying to get headings i.e.

====================
Monday June 10th
entry 1
entry 2
entry 3

Tuesday June 11th
entry 1
entry 2
entry 3

====================

Thanks
#2

[eluser]Michael Wales[/eluser]
In your view:
Code:
<?php
  $cur_date = '';
  foreach ($result as $listing) {
    if ($listing->postdate != $cur_date) {
      echo date('l, F jS', strtotime($listing->postdate));
      $cur_date = $listing->postdate;
    }
    echo $listing->title;
  }
?>
#3

[eluser]mikeyhell[/eluser]
thanks, was racking my brain for no reason.
#4

[eluser]hyperfire[/eluser]
thats a great solution, but what would be the solution to show 'empty' dates when no records for a specific date is not found?
Something like:

2009-01-29
- record 1
- record 2
2009-01-30
no records available
2009-01-31
- record 1
- record 2
.... and so on
#5

[eluser]obiron2[/eluser]
Create a new array for all your dates $datesarray()

on change of date in the data array, move the $datesarray pointer and compare the value to the next record in the data array. If they do not match, output the $datearray() value and 'no entries'

repeat until the data array date matches the $datearray() date.

Obiron
#6

[eluser]hyperfire[/eluser]
I like the idea, but I don't know how to compare a value to the 'next record' inside a foreach loop. Is that possible?




Theme © iAndrew 2016 - Forum software by © MyBB