【问题标题】:How to make an logic to separate the data from SQL with Cakephp2?如何使用 Cakephp2 制定逻辑将数据与 SQL 分离?
【发布时间】:2017-06-07 05:44:19
【问题描述】:

目前,我有一个站点,其中显示了我从 Cakephp2 数据库中的 MySQL 中提取的开发人员名称列表。我想要实现的是将“开发人员”分为“开发人员”和“程序员”两种类型。我试图为 id 提供一个额外的字段,以将开发人员与包含开发人员姓名的表中的程序员分开。但我坚持如何做到这一点。我的解释可能令人困惑,所以我将把我想做的示例放在下面。一些技巧和例子会有很大的帮助。我很想听听你的意见。

    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

【问题讨论】:

    标签: php mysql sql cakephp-2.0


    【解决方案1】:

    我并没有完全得到您的要求,但根据您的表格结构,您可以执行类似的操作。

         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')
        ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多