1. <legend id='9dWLS'><style id='9dWLS'><dir id='9dWLS'><q id='9dWLS'></q></dir></style></legend>

      <tfoot id='9dWLS'></tfoot>
      <i id='9dWLS'><tr id='9dWLS'><dt id='9dWLS'><q id='9dWLS'><span id='9dWLS'><b id='9dWLS'><form id='9dWLS'><ins id='9dWLS'></ins><ul id='9dWLS'></ul><sub id='9dWLS'></sub></form><legend id='9dWLS'></legend><bdo id='9dWLS'><pre id='9dWLS'><center id='9dWLS'></center></pre></bdo></b><th id='9dWLS'></th></span></q></dt></tr></i><div id='9dWLS'><tfoot id='9dWLS'></tfoot><dl id='9dWLS'><fieldset id='9dWLS'></fieldset></dl></div>
          <bdo id='9dWLS'></bdo><ul id='9dWLS'></ul>
      1. <small id='9dWLS'></small><noframes id='9dWLS'>

        如何在 ZF 表界面中进行联接查询?

        How to do a joined query in the ZF tables interface?(如何在 ZF 表界面中进行联接查询?)
          <legend id='V6Exk'><style id='V6Exk'><dir id='V6Exk'><q id='V6Exk'></q></dir></style></legend>
            <i id='V6Exk'><tr id='V6Exk'><dt id='V6Exk'><q id='V6Exk'><span id='V6Exk'><b id='V6Exk'><form id='V6Exk'><ins id='V6Exk'></ins><ul id='V6Exk'></ul><sub id='V6Exk'></sub></form><legend id='V6Exk'></legend><bdo id='V6Exk'><pre id='V6Exk'><center id='V6Exk'></center></pre></bdo></b><th id='V6Exk'></th></span></q></dt></tr></i><div id='V6Exk'><tfoot id='V6Exk'></tfoot><dl id='V6Exk'><fieldset id='V6Exk'></fieldset></dl></div>
          • <small id='V6Exk'></small><noframes id='V6Exk'>

              <tbody id='V6Exk'></tbody>
            <tfoot id='V6Exk'></tfoot>

              <bdo id='V6Exk'></bdo><ul id='V6Exk'></ul>

                1. 本文介绍了如何在 ZF 表界面中进行联接查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有数据库,我的表是这样的:

                  I have the db and my tables look like this:

                  替代文字 http://img15.imageshack.us/img15/2568/stackdijag.png

                  我想要做的是获取制造商名称列以 A 开头的所有型号.这意味着查询的简单部分应该像 $manufacturers->fetchAll("name LIKE '$letter%'");

                  What I want to do is to get all models where manufacturers name column starts with A. Which means that that simple part of query should be like $manufacturers->fetchAll("name LIKE '$letter%'");

                  我正试图通过 ZF 关系来实现这一点,但它不会成功,因此欢迎任何形式的帮助......

                  I am trying to accomplish this with ZF relations but it ain't going, so any kind of help is welcome...

                  推荐答案

                  $models = new Models();
                  $select = $models->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
                  $select->setIntegrityCheck(false)
                         ->join(array("a"=>"manufacturers"), 'models.manufacturer_id = a.id',
                           array("man_name"=>"name", "man_description"=>"description"))
                         ->where("a.name LIKE 'A%'");
                  $rowset = $models->fetchAll($select);
                  

                  不幸的是,Zend_Db_Table 关系接口在从其声明的参考映射创建连接查询方面没有太多智能.复杂查询的社区贡献解决方案是 Zend_Db_Table_Select 查询工厂.

                  Unfortunately the Zend_Db_Table relationships interface doesn't have much intelligence in it related to creating joined queries from its declared reference map. The community-contributed solution for complex queries is the Zend_Db_Table_Select query factory.

                  请注意,您必须为制造商的名称和描述提供列别名,否则这些列将抑制行数据关联数组中的模型名称和描述.您应该清楚地命名列以避免这种情况.

                  Note you have to give column aliases for manufacturer's name and description, or else these columns will suppress the model's name and description in the associative array for the row data. You should name columns distinctly to avoid this.

                  但在你的情况下,我会跳过表接口和选择接口,直接使用数据库适配器直接执行 SQL 查询:

                  But in your case, I'd skip the table interface and the select interface, and simply execute an SQL query directly using the Db adapter:

                  $data = $db->fetchAll("
                    SELECT m.*, a.name AS man_name, a.description AS man_description
                    FROM Models m JOIN Manufacturers a ON m.manufacturer_id = a.id
                    WHERE a.name LIKE 'A%'");
                  

                  您将把数据作为一个简单的关联数组数组返回,而不是作为 Zend_Db_Table_Rowset.但由于联接的行集无论如何都不可写,因此您并没有做出太多牺牲.

                  You'll get the data back as a simple array of associative arrays, not as a Zend_Db_Table_Rowset. But since a joined rowset isn't writeable anyway, you haven't sacrificed much.

                  这篇关于如何在 ZF 表界面中进行联接查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)
                  MySQL cumulative sum grouped by date(按日期分组的 MySQL 累计总和)
                    <legend id='CC92k'><style id='CC92k'><dir id='CC92k'><q id='CC92k'></q></dir></style></legend>
                    <i id='CC92k'><tr id='CC92k'><dt id='CC92k'><q id='CC92k'><span id='CC92k'><b id='CC92k'><form id='CC92k'><ins id='CC92k'></ins><ul id='CC92k'></ul><sub id='CC92k'></sub></form><legend id='CC92k'></legend><bdo id='CC92k'><pre id='CC92k'><center id='CC92k'></center></pre></bdo></b><th id='CC92k'></th></span></q></dt></tr></i><div id='CC92k'><tfoot id='CC92k'></tfoot><dl id='CC92k'><fieldset id='CC92k'></fieldset></dl></div>
                    1. <tfoot id='CC92k'></tfoot>

                          <bdo id='CC92k'></bdo><ul id='CC92k'></ul>

                            <small id='CC92k'></small><noframes id='CC92k'>

                              <tbody id='CC92k'></tbody>