lundi 29 juin 2015

SORT BY DATE sqlite does not work like normal sql? can I use php function to sort?

Hi guys so i am using an sqLite database in wich i have a table called "calender".

This table contains the following columns: id -INTEGER titel -VARCHAR beschrijving -VARCHAR datum -DATETIME inhoud -TEXT album -VARCHAR

Anyway: I am storing my dates like this: "03-01-2015" So thats: d - m - Y.

However when I run my sqlQuery to select them I cannot use ORDER BY datum. This does not order them! the sql function STR_TO_DATE('datum','%d,%m,%Y') Doesnt seem to exist either in sqLite and returns an error "no such function".(I am not even saving dates as a string though but as actual DATETIMES so this is not the problem)

Anyway i am showing the data from my table like this:

 while ($x = $resultGetAllCalender->fetchObject()){
    $html .="    
      <div class='col-md-4'>             
          <div class='col-sm-10 kalenderTopic'>
              <div class='datum'><strong>Datum: <span>$x->datum</span></div>
              <div class='datum'>Activiteit: <span>$x->titel</span></div>
              <div class='inhoud'>$x->beschrijving</div>
              <div class='readMore'><a href='index.php?page=kalenderDetail&id=$x->id'>Meer informatie</a>
           </div>
       </div>

End i echo out my $html later.

So i was thinking. Maybe i can sort the result of $resultGetAllCalender->FetchObject() first (using a php function like usort()) Before running a while loop to add all my data to my $html variable.

However I am confused I cant seem to sort result of my fetch either. Any tips are very welcome, I'll keep crushing my brain in the meanwhile!

Edit: my method that contains the query: (i am no longer using any ORDER BY since this was not working)

 public function getAllKalender(){
        $sql = "SELECT * FROM kalender";
        $statement = $this->makeStatement($sql); 
        return $statement;
    }

Aucun commentaire:

Enregistrer un commentaire