title: if function inside sql query?
body: <pre><code>function get_tags_by_criteria($gender_id, $country_id, $region_id, $city_id, $day_of_birth=NULL, $tag_id=NULL, $thread_id=NULL) {
  
      $query = "SELECT tags.*
          FROM tags, thread_tag_map, threads
          WHERE thread_tag_map.thread_id = threads.id
          AND thread_tag_map.tag_id = tags.id
  
          AND threads.gender_id = $gender_id
          AND threads.country_id = $country_id
          AND threads.region_id = $region_id
          AND threads.city_id = $city_id
          AND tags.id LIKE '%$tag_id%'
          AND threads.id LIKE '%$thread_id%'";
          if(!$day_of_birth)
          {
              $query += "AND threads.min_day_of_birth &lt;= '$day_of_birth AND threads.max_day_of_birth &gt;= '$day_of_birth' ";
          }
  
          $query += "GROUP BY tags.name";
  
      $result = $this-&gt;do_query($query);
      return $result;
  }
  </code></pre>
  
  <p>if no $day_of_birth is passed as an argument i want the sql to omit the 2 lines inside the if. i used:</p>
  
  <pre><code>$all_tags = $forum_model-&gt;get_tags_by_criteria(1, 1, 0, 0);
  </code></pre>
  
  <p>i wonder why this sql returns a error:</p>
  
  <pre><code>Couldn't execute query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1
  </code></pre>