2015-06-26 83 views
-1

我有兩個變量$ faceplateInstalled和$ faceplateExists,我把它們打印成兩列刪除重複行,如果兩個變量匹配PHP

Faceplate Exists Faceplate Instaled 
1       1 
1       0 
1       1 
0       0 
1       1 
1       0 
1       1 
1       1 
0       0 
0       0 
1       0 

有沒有一種方法,以消除在那裏我一個相同的1和1項行?

這是一個查詢使用:

"SELECT F.id AS faceplateId, PR.premiseId, ComposeAddressFromPAF(PR.postAddressId) AS fullAddress, " . 
      " IF(F.id IS NOT NULL, 1, 0) AS faceplateExists, " . 
      " IFNULL(F.installed, 0) AS faceplateInstalled, " . 
      " PR.siteId, S.NAME AS siteName " . 
      "FROM ho_crm_premise PR " . 
      " LEFT JOIN ho_faceplate F ON F.premiseId = PR.premiseId " . 
      " INNER JOIN bcube_site S ON S.SITEID = PR.siteId " . 
      "WHERE S.SITEID"; 

,這是全功能

function GetFaceplates($siteId) 
    { 
     $sSql = 
      "SELECT F.id AS faceplateId, PR.premiseId, ComposeAddressFromPAF(PR.postAddressId) AS fullAddress, " . 
      " IF(F.id IS NOT NULL, 1, 0) AS faceplateExists, " . 
      " IFNULL(F.installed, 0) AS faceplateInstalled, " . 
      " PR.siteId, S.NAME AS siteName " . 
      "FROM ho_crm_premise PR " . 
      " LEFT JOIN ho_faceplate F ON F.premiseId = PR.premiseId " . 
      " INNER JOIN bcube_site S ON S.SITEID = PR.siteId " . 
      "WHERE S.SITEID"; 

     if($siteId) 
     { 
      $sSql .= " AND PR.siteId = " . $siteId . " "; 
     } 

     $pResult = $this->ExecuteSQL($sSql); 
     return $pResult; 
    } 


$db = new DatabaseInfinity(); 

$action = $_REQUEST["action"]; 

//$action = "SEARCH"; // TEMPORARY 
$siteId = $_REQUEST["siteId"]; 

if($action == "SEARCH") 
{ 
    $faceplates = $db->GetFaceplates($siteId); 

    while($faceplate = FetchObject($faceplates)) 
    { 
     $tpl->newBlock("FACEPLATE"); 
     $tpl->assign("ID", $faceplate->faceplateId); 
     $tpl->assign("PREMISEID", $faceplate->premiseId ); 
     $tpl->assign("ADDRESS", $faceplate->fullAddress); 
     $tpl->assign("SITEID", $faceplate->siteId); 
     $tpl->assign("SITENAME", $faceplate->siteName); 
     $tpl->assign("FEXISTS", $faceplate->faceplateExists); 
     $tpl->assign("FINSTALED", $faceplate->faceplateInstalled); 
    } 
} 
+0

數據存儲爲數組?或者作爲一個字符串......? –

+0

歡迎來到Stack Overflow!這個問題在信息上有點短暫。你可以分享你的嘗試,以及你遇到了什麼問題? –

+0

這會讓所有人都猜到,*不是Sam嗎?* - @JayBlanchard現在已經發布了一個答案,並且在事實*之後獲得了某些內容*。 Oufff! –

回答

0

根據您的後期編輯,你可以改變你的查詢,包括條件faceplateExists <> faceplateInstalled在外部查詢到得到如下所需的結果

SELECT * FROM 
(
SELECT F.id AS faceplateId, PR.premiseId, 
ComposeAddressFromPAF(PR.postAddressId) AS fullAddress, " . 
      " IF(F.id IS NOT NULL, 1, 0) AS faceplateExists, " . 
      " IFNULL(F.installed, 0) AS faceplateInstalled, " . 
      " PR.siteId, S.NAME AS siteName " . 
      "FROM ho_crm_premise PR " . 
      " LEFT JOIN ho_faceplate F ON F.premiseId = PR.premiseId " . 
      " INNER JOIN bcube_site S ON S.SITEID = PR.siteId " . 
      "WHERE S.SITEID 
) XXX WHERE faceplateExists <> faceplateInstalled; 
+0

i'v完成了左加入,所以我沒有一張桌子在哪裏可以做到這一點,而且我不想刪除記錄我只想不顯示他們 –

+0

請不要在註釋中轉儲代碼 –

+0

@MilosMarkovic,應該讓人們早點知道,反正如果有幫助,請參閱編輯。 – Rahul