开发者

Mysql returns 0 rows when there is a value in the database. using Cakephp

I have a table called 'projects', that has a column called project_title Below is the sql code. I did all of this in cake by the way. I can show you my cake code as well as the sql query generated below.

function search()
{
   if (!empty($this->data)): 
     $keywords = Array();
     $keywords['categories'] = array();

     $categories = $this->data['Project']['ProjectCategory'];
     if($categories): 
       foreach($categories as $category):
         $keywords['categories'][] = $category;
       endforeach;
     endif;

     $queries = str_replace(",", "",$this->data['Project']['query']);
     $keywords['project_title'] = explode(" ", $queries);

     $nq = '';

     foreach($keywords as $key =>$value)
     {
       if($key == 'project_title'):
         foreach($value as $q):
           $nq[] = array('Project.project_title LIKE'=>"%$q%");
         endforeach;
       elseif($key == 'categories'):
         foreach($value as $q):
           $nq[] = array('Category.id'=>"$q");
         endforeach;
       endif;
     }

     $final = array("OR"=>$nq);
     $joins = '';//array('table'=>'users','alias'=>'User','type' =>
                 //'LEFT','conditions'=>'User.id = Project.user_id'); 
     $options = array('conditions'=>$final);

     $projects = $this->Project->ProjectCategory->find('all',$options);
     $this->set('pro开发者_StackOverflowjects',$projects);
     $this->paginate();

   endif;
 }

This query is generated:

SELECT * FROM `project_categories` AS `ProjectCategory` 
LEFT JOIN `projects` AS `Project` 
       ON (`ProjectCategory`.`project_id` = `Project`.`id`) 
LEFT JOIN `categories` AS `Category` 
       ON (`ProjectCategory`.`category_id` = `Category`.`id`) 
WHERE `Project`.`project_title` LIKE '%test%'

as you can see, I am joining 2 other tables. But is resides here

WHERE `Project`.`project_title` LIKE '%test%'

In projects, I have 3 records that have the word test under project title. I will list them below

Ryans Test Project
Ryans Test Project 2
Test project #2
Money Aint A Thang

I receive no errors, I just get a zero result.

What's wrong?


Are you using a case-sensitive collation on the project_title column? If so, that would explain why searching for test doesn't match rows that contain Test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜