2017-06-07 59 views
0

目前,我有一個網站,顯示了我從CakePHP2中的數據庫中的MySQL中取出的開發人員名單。我想要實現的是將「開發人員」分成兩種類型,例如「開發人員」和「程序員」。我試圖給id添加一個額外的字段,以便將開發人員與包含開發人員名稱的表中的程序員分開。但我堅持我如何做到這一點。我的解釋可能會令人困惑,所以我會把我想要做的樣本放在下面。一些提示和例子非常有幫助。我很想聽到你的消息。如何使用Cakephp2從SQL中分離數據的邏輯?

Currently, Employee table consitsts of list of names 
    of all developers and is retrieved and displayed in cakephp2. 
      (Developer) 
        ------------------------------ 
         Tim 
         Jim 
         Joe 
         Blake 
         Mike 
         Ron 
       ------------------------------ 

      Now, I want to separate the Developers into two parts "Developer" and "Programmer" maybe by adding a programmer_id field . 

       (Developers) 
       ------------------------------ 
         Tim 
         Jim ← programmer_id 
         Joe 
         Blake 
         Mike ← programmer_id 
         Ron 
       ------------------------------ 

Want to show the separated data in cakephp2 like the following. 


       (Developer) 
         Tim 
         Joe 
         Blake 
         Ron 

       ------------------------------ 
       (Programmer) 
         Jim 
         Mike 

回答

0

我沒有得到你問什麼,但按照你的表結構,你可以做這樣的事情。

 developer Tim 
    programer Jim ← programmer_id 
    developer Joe 
    developer Blake 
    programer Mike ← programmer_id 
    developer Ron 

    $developer = $this->Employee->find('all', array(
     'conditions' => array('Employee.category' => 'developer') 
    )); 

    $programmer = $this->Employee->find('all', array(
     'conditions' => array('Employee.category' => 'programmer') 
    ));