Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 23rd, 2012  |  syntax: None  |  size: 2.72 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to put if else condition in LIMIT mysql
  2. $where_or = "
  3.                 AND
  4.                     content_status = 'Active'
  5.                 AND
  6.                     content_post_status = 'published'
  7.                 AND
  8.                     deleted = 0
  9.                 AND
  10.                     content_type = '$type'
  11.                 ORDER BY content_created_at DESC ";
  12.  
  13.         $select = "content_id, content_title, content_short_description, content_url, content_created_at";
  14.  
  15.         $query = $this->db->query("
  16.                 (
  17.                     SELECT $select
  18.                     FROM tbl_content
  19.                     WHERE
  20.                     content_category_id = 54
  21.                     $where_or
  22.                     LIMIT 3
  23.                 )
  24.                 UNION ALL
  25.                 (
  26.                     SELECT $select
  27.                     FROM tbl_content
  28.                     WHERE
  29.                     content_category_id = 55
  30.                     $where_or
  31.                     LIMIT 2
  32.                 )
  33.                 UNION ALL
  34.                 (
  35.                     SELECT $select
  36.                     FROM tbl_content
  37.                     WHERE
  38.                     content_category_id = 56
  39.                     $where_or
  40.                     LIMIT 2
  41.                 )
  42.                 UNION ALL
  43.                 (
  44.                     SELECT $select
  45.                     FROM tbl_content
  46.                     WHERE
  47.                     content_category_id = 57
  48.                     $where_or
  49.                     LIMIT 1
  50.                 )
  51.                 UNION ALL
  52.                 (
  53.                     SELECT $select
  54.                     FROM tbl_content
  55.                     WHERE
  56.                     content_category_id = 58
  57.                     $where_or
  58.                     LIMIT 1
  59.                 )
  60.                 UNION ALL
  61.                 (
  62.                     SELECT $select
  63.                     FROM tbl_content
  64.                     WHERE
  65.                     content_category_id = 60
  66.                     $where_or
  67.                     LIMIT 1
  68.                 )
  69.                 UNION ALL
  70.                 (
  71.                     SELECT $select
  72.                     FROM tbl_content
  73.                     WHERE
  74.                     content_category_id = 61
  75.                     $where_or
  76.                     LIMIT 1
  77.                 )
  78.                 UNION ALL
  79.                 (
  80.                     SELECT $select
  81.                     FROM tbl_content
  82.                     WHERE
  83.                     content_category_id = 118
  84.                     $where_or
  85.                     if content_type = 'article'
  86.                     begin
  87.                         LIMIT 10
  88.                     end
  89.                 )  
  90.         ");
  91.        
  92. if content_type = 'article'
  93. begin
  94.    LIMIT 10
  95. end