php - Doctrine --- search -
we use zend frame work , doctrine data base. problem want search string (for example: testin'g) string "single quotes". doctrine query fails retrives data query joins , works fine normal query out joins.
my method
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 .=" , c.news_type = 1"; } else if($letterpressed == 'google news') { $where .=" , c.news_type = 3"; } else if($letterpressed == 'google blogs') { $where .=" , c.news_type = 4"; } else if($letterpressed == 'hide twitter') { $where .=" , c.url not '%twitter.com%'"; } else if($letterpressed == 'hide facebook') { $where .=" , c.url not '%facebook.com%'"; } else if($letterpressed == 'hide facebook-twitter') { $where .=" , c.url not '%twitter.com%' , c.url not '%facebook.com%'"; } else if($letterpressed == 'show twitter') { $where .=" , c.url '%twitter.com%'"; } else if($letterpressed == 'show facebook') { $where .=" , c.url '%facebook.com%'"; } else if($letterpressed == 'show facebook-twitter') { $where .=" , c.url '%twitter.com%' or c.url '%facebook.com%'"; } if($queryv!='' && (trim($letterpressed) != 'law' && trim($letterpressed) != 'ls translate')){ $search = ' c.title "%'.mysql_real_escape_string($queryv).'%" '; } $select='c.id, c.campaign_id, c.title 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 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 title, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state'; if($queryv!='') $search = ' t.raw_title "%'.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 title, t.language_id, t.tr_translated_date, t.tr_translated_by, t.translation_state'; $where .=" , t.translation_state = 1"; if($queryv!='') $search = ' t.tr_title "%'.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 output query , run in query browser works fine. */ $pager = new doctrine_pager($query,$currentpage, $resultsperpage);// here fails retrive data return $pager;//print_r($pager);exit;
instead of addwhere try use andwhere()
Comments
Post a Comment