title: 500 Internal server error after changing mysql query
body: <p>Yesterday I changed my database schema, and consequently a database query in my application, since then I have been receiving 500 Internal Server Errors. I do not think that the problem is the query, as I can run it from my model, and print the array from my controller. The problem seems to be when building the template. </p>
  
  <p>Below is my code, </p>
  
  <p><strong>MODEL</strong>  </p>
  
  <pre><code>public function searchCandidates($type=null, $gender=null, $age=null)
      {
          if($age != "0") {
              $age = implode(", %",$age);
          }
  
          $sql = 'SELECT `candidates`.`candidate_id`, 
                          `candidates`.`first_name`, 
                          `candidates`.`surname`, 
                          `candidates`.`DOB`, 
                          `candidates`.`gender`, 
                          `candidates`.`talent`, 
                          `candidates`.`location`, 
                          `candidates`.`availability`,
                          `candidates`.`youtube_showreel_1`,
                          `candidates`.`youtube_showreel_2`,
                          `candidates`.`youtube_showreel_3`,
                          `candidates`.`youtube_showreel_4`,
                          `candidates`.`youtube_showreel_5`,
                          `candidates`.`youtube_showreel_desc_1`,
                          `candidates`.`youtube_showreel_desc_2`,
                          `candidates`.`youtube_showreel_desc_3`,
                          `candidates`.`youtube_showreel_desc_4`,
                          `candidates`.`youtube_showreel_desc_5`,
                          `candidates`.`date_created`,
                           DATE_FORMAT(NOW(), "%Y") - DATE_FORMAT(`candidates`.`DOB`, "%Y") - (DATE_FORMAT(NOW(), "00-%m-%d") &lt; DATE_FORMAT(`candidates`.`DOB`, "00-%m-%d")) as `age`,
                          `candidate_assets`.`url`, 
                          `candidate_assets`.`asset_size`
                  FROM `candidates`
                  LEFT JOIN `candidate_assets` ON `candidate_assets`.`candidates_candidate_id` = `candidates`.`candidate_id`
                  WHERE `candidates`.`availability` = "yes"';
                  //is there a certain criteria
                  if($type != "0") { $sql .= 'AND `candidates`.`talent` = '.$type; }
                  if($age != "0") { $sql .= 'AND `candidates`.`playing_age` LIKE "%'.$age.'%"';}
                  if($gender != false){ $sql .= 'AND `candidates`.`gender` = '.$gender; }
                  $sql .= ' GROUP BY `candidates`.`candidate_id`';
  
          $query = $this-&gt;db-&gt;query($sql);
  
          //die(print_r($query-&gt;result_array()));
  
          //die($this-&gt;db-&gt;last_query());
          return $query-&gt;result_array();
      }
  </code></pre>
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>$data['results'] = 
  
  $this-&gt;candidates_model-&gt;searchCandidates($this-&gt;input-&gt;post('type'), $this-&gt;input-&gt;post('gender'), $this-&gt;input-&gt;post('age')); 
              $this-&gt;session-&gt;set_userdata('search', $data['results']);
              //die(print_r($this-&gt;session-&gt;userdata('search')));
              $this-&gt;template-&gt;build('search/results', $data);
  </code></pre>
  
  <p>The error in my error logs looks like this, </p>
  
  <blockquote>
    <p>[Fri Dec 09 10:28:49 2011] [error] [client xx.xx.xx.xxx] malformed
    header from
          script. Bad header=Bs%3A2%3A%2259%22%3Bs%3A10%3A%:   index.php, referer:  <a href="http://urbantalent.factoryagency.co.uk/search" rel="nofollow">http://urbantalent.factoryagency.co.uk/search</a></p>
  </blockquote>