php - Mysql use DESC in case statement -


in below sql command want use desc after when 1 i.id line. want if sortable field 1 order must have command,

order i.id desc 

mysql :

  select       sql_calc_found_rows i.* ,       c.title category_name,       u.name,       u.family,       i.thumb_image,      concat( u.name, ' ', u.family ) author,      tumbnail_image_width,      tumbnail_image_height     contents   join   categories c on c.id = i.category   join   users u on u.id = i.posted_by   join   settings s on s.portal = i.portal             i.portal = '{$portal_id}'          , case when post_type = 4               date(now()) between i.from_datetime , i.to_datetime           else post_type = 1          end   , i.t_status = 1   order      case (select sortable settings)         when 1 i.id          when 2 i.date_time         when 3 i.order_display      end                            limit {$portalsettings['display_post_count']};";    

possibly bring sort field in select , sort named field:-

  select       sql_calc_found_rows i.* ,       c.title category_name,       u.name,       u.family,       i.thumb_image,      concat( u.name, ' ', u.family ) author,      tumbnail_image_width,      tumbnail_image_height,      case (s.sortable)         when 1 100000000 - i.id          when 2 i.date_time         when 3 i.order_display      end  sortfield     contents   join   categories c on c.id = i.category   join   users u on u.id = i.posted_by   join   settings s on s.portal = i.portal             i.portal = '{$portal_id}'          , case when post_type = 4               date(now()) between i.from_datetime , i.to_datetime           else post_type = 1          end   , i.t_status = 1   order sortfield                     limit {$portalsettings['display_post_count']};"; 

note might have cast fields data type this.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -