2016-08-03 34 views
-2

這張圖片是我的MySQL表格。 enter image description here我只想在結果中的用戶表中的行

這些是我的代碼。

$buyuser = CHtml::encode($_POST['buyuser']); 
      $criteria = new CDbCriteria; 
      $criteria->distinct = FALSE; 
      $criteria->with = array('addresses'=>array('alias'=>'adres', 'together'=>true),'addresses.city'=>array('alias'=>'city', 'together'=>true)); 
      $criteria->addCondition('t.name LIKE "'.$buyuser.'%" OR t.name LIKE "% '.$buyuser.'%" OR t.lastname LIKE "'.$buyuser.'%" OR t.lastname LIKE "% '.$buyuser.'%" OR adres.store LIKE "'.$buyuser.'%" OR adres.store LIKE "% '.$buyuser.'%" OR city.name LIKE "'.$buyuser.'%" OR city.name LIKE "% '.$buyuser.'%"'); 
      $users = Users::model()->findAll($criteria); 

它的工作,但我想也看到重複的記錄時city.name或姓氏或商店是一個。 我需要所有地址。

+1

就在方評論,下次你可以粘貼SQL代碼或類似MySQL工作臺工具的圖像:https://www.mysql.com/products/workbench/ – Eduardo

回答

0

我改變了findAll中的基表和我的答案。

$buyuser = CHtml::encode($_POST['buyuser']); 
     $criteria = new CDbCriteria; 
     $criteria->distinct = FALSE; 
     $criteria->with = array('user'=>array('together'=>true),'city'=>array('together'=>true)); 
     $criteria->addCondition('user.name LIKE "'.$buyuser.'%" OR user.name LIKE "% '.$buyuser.'%" OR user.lastname LIKE "'.$buyuser.'%" OR user.lastname LIKE "% '.$buyuser.'%" OR CONCAT(user.name," ",user.lastname) LIKE "'.$buyuser.'%" OR CONCAT(user.name," ",user.lastname) LIKE "% '.$buyuser.'%" OR t.store LIKE "'.$buyuser.'%" OR t.store LIKE "% '.$buyuser.'%" OR city.name LIKE "'.$buyuser.'%" OR city.name LIKE "% '.$buyuser.'%"'); 
     $addresses = Addresses::model()->findAll($criteria); 
+1

您所需要的所有地址或所有用戶與所有地址? – Eduardo

相關問題