php - Order by CASE ASC -
PDO (mysql database) for the first time using CASE in
I'm trying to order a date I am, but only when not on 0000-00-00 (it may be)
but it seems that the case all ignoring together .. I'm doing wrong?
$ sql = 'SELECT * mytable from WHERE groupid ='. $ Groupid Based on the order when grouped! = "0000-00-00" then group Aided 'ASC'; $ STH = $ conn- & gt; Query ($ sql); If & ($ STH- & gt; rowCount () gt; 0) {while ($ row = $ STH- & gt; fetch ()) {// Lines output}} Other {echo '& lt; P & gt; No dates found & lt; / P & gt; '; }
What do you want to do with zero-date rows? After them the other lines?
then the query using
SELECT * mytable the WHERE groupid = $ groupid ORDER by groupdate = '0000-00-00', groupdate
< P> groupdate = '0000-00-00' is a boolean expression and 1 for matching rows gives 0 for non-matching lines. 0 comes in ascending order before 1. Non-zero rows are sorted by group.
Comments
Post a Comment