我們使用zend的框架和工作原理數據庫。 現在我的問題是我想搜索一個字符串(例如:testin'g)與「單引號」字符串。 原則查詢無法爲連接的查詢檢索數據,並且可以正常查詢且無連接。學說---搜索
我的方法是相反addWhere的
public function getNewsListGrid($campid,$currentPage,$resultsPerPage,$quickSearchType,$queryv,$sortName,$sortOrder,$letterPressed)
{
$query = new Doctrine_Query();
$whereCond ='';
$where='eng.id='.$campid;
$select='';
$search = '';
if($letterPressed == 'All')
{
$where .="";
}
else if($letterPressed == 'Radian6')
{
$where .=" AND c.news_type = 1";
}
else if($letterPressed == 'Google News')
{
$where .=" AND c.news_type = 3";
}
else if($letterPressed == 'Google Blogs')
{
$where .=" AND c.news_type = 4";
}
else if($letterPressed == 'Hide Twitter')
{
$where .=" AND c.url NOT LIKE '%twitter.com%'";
}
else if($letterPressed == 'Hide Facebook')
{
$where .=" AND c.url NOT LIKE '%facebook.com%'";
}
else if($letterPressed == 'Hide Facebook-twitter')
{
$where .=" AND c.url NOT LIKE '%twitter.com%' AND c.url NOT LIKE '%facebook.com%'";
}
else if($letterPressed == 'Show Twitter')
{
$where .=" AND c.url LIKE '%twitter.com%'";
}
else if($letterPressed == 'Show Facebook')
{
$where .=" AND c.url LIKE '%facebook.com%'";
}
else if($letterPressed == 'show Facebook-twitter')
{
$where .=" AND c.url LIKE '%twitter.com%' OR c.url LIKE '%facebook.com%'";
}
if($queryv!='' && (trim($letterPressed) != 'Law' && trim($letterPressed) != 'Ls Translate')){
$search = ' c.title like "%'.mysql_real_escape_string($queryv).'%" ';
}
$select='c.id, c.campaign_id, c.title as title, c.domain, c.news_type,c.url, c.active, c.article_date, c.created_date, c.modified_date, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state, t.tr_title, t.raw_title';
if(trim($letterPressed) == 'Original')
{
$select='c.id, c.campaign_id, c.title as title, c.domain, c.news_type,c.url, c.active, c.article_date, c.created_date, c.modified_date, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state';
}
if(trim($letterPressed) == 'Law')
{
$select='c.id, c.campaign_id, c.domain, c.news_type,c.url, c.active,c.article_date, c.created_date, c.modified_date, t.raw_title as title, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state';
if($queryv!='')
$search = ' t.raw_title like "%'.mysql_real_escape_string($queryv).'%" ';
}
if(trim($letterPressed) == 'Ls Translate')
{
$select='c.id, c.campaign_id, c.domain, c.news_type,c.url, c.active, c.article_date, c.created_date, c.modified_date, t.tr_title as title, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state';
$where .=" AND t.translation_state = 1";
if($queryv!='')
$search = ' t.tr_title like "%'.mysql_real_escape_string($queryv).'%" ';
}
$whereCond.=$where;
$query->select($select)
->from('News c')
->leftJoin('c.TranslatedNews t')
->leftJoin('c.Campaigns eng')
->where($whereCond)
->addWhere('eng.tr_language_id=t.language_id')
->orderBy('c.'.$sortName. ' ' . $sortOrder)
->groupBy('c.title')
->addGroupBy('c.url');
if(!empty($search))
$query->addWhere($search);
//echo $query->getSqlQuery();exit;
/*
here when i output query and run in any query browser it works fine.
*/
$pager = new Doctrine_Pager($query,$currentPage, $resultsPerPage);// here it fails to retrive data
return $pager;//print_r($pager);exit;
我試過,但沒有工作 – user1155659 2011-05-11 09:28:57