<legend id='GPbMY'><style id='GPbMY'><dir id='GPbMY'><q id='GPbMY'></q></dir></style></legend>

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

  • <i id='GPbMY'><tr id='GPbMY'><dt id='GPbMY'><q id='GPbMY'><span id='GPbMY'><b id='GPbMY'><form id='GPbMY'><ins id='GPbMY'></ins><ul id='GPbMY'></ul><sub id='GPbMY'></sub></form><legend id='GPbMY'></legend><bdo id='GPbMY'><pre id='GPbMY'><center id='GPbMY'></center></pre></bdo></b><th id='GPbMY'></th></span></q></dt></tr></i><div id='GPbMY'><tfoot id='GPbMY'></tfoot><dl id='GPbMY'><fieldset id='GPbMY'></fieldset></dl></div>
    <tfoot id='GPbMY'></tfoot>

          <bdo id='GPbMY'></bdo><ul id='GPbMY'></ul>
      1. 来自数据库的系谱/家谱图

        时间:2023-10-03

          <tbody id='i90V6'></tbody>
      2. <legend id='i90V6'><style id='i90V6'><dir id='i90V6'><q id='i90V6'></q></dir></style></legend>
        • <bdo id='i90V6'></bdo><ul id='i90V6'></ul>

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

            <tfoot id='i90V6'></tfoot>

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

                • 本文介绍了来自数据库的系谱/家谱图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从数据库生成谱系(换句话说,家谱:))表...

                  I am trying to generate pedigree (in other words family tree :) ) table from database...

                  我的架构:

                  CREATE TABLE `horses` ( 
                  `horse_id` int(10) NOT NULL AUTO_INCREMENT,
                  `horse_name` varchar(32) NOT NULL,
                  `horse_sire` int(10) DEFAULT NULL,
                  `horse_dam` int(10) DEFAULT NULL, 
                  PRIMARY KEY (`horse_id`),
                  KEY `FKsire` (`horse_sire`),
                  KEY `FKdam` (`horse_dam`),
                  CONSTRAINT `FKdam` FOREIGN KEY (`horse_dam`) REFERENCES `horses` (`horse_id`),
                  CONSTRAINT `FKsire` FOREIGN KEY (`horse_sire`) REFERENCES `horses` (`horse_id`)
                  )
                  

                  附言'horse_dam' 和 'horse_sire' 代表父母......我在这个问题上花了几天时间,搜索,试验......目前我有这个部分解决方案:

                  p.s. 'horse_dam' and 'horse_sire' represents parents... I have spent days on this problem, searching, experimenting... And currently I have this partly solution:

                  display_children($selected_horse_id, 5);
                  
                          function display_children($parent, $level) {
                              mysql_connect('localhost','root','');
                              mysql_select_db('hdb');
                              $result = mysql_query('SELECT * FROM horses WHERE horse_id="'.$parent.'";');
                  
                  
                              while ($row = mysql_fetch_array($result)) {
                  
                                  echo "<tr><td>";
                                  echo $row['horse_name'];
                                  echo "</td></tr>";
                  
                                  display_children($row['horse_dam'], $level+1);
                                  display_children($row['horse_sire'],$level+1);
                              }
                          }
                  

                  在一行中生成表:(我想不出正确的方法来实现它......我想要的结果是 谱系查询

                  which generates table in one row :( I cannot think of proper way to implement it... And the result I want is Pedigree Query

                  非常感谢任何帮助或提示:),提前致谢

                  Any help or hint is highly appreciated :), Thanks in advance

                  推荐答案

                  我几个月前已经解决了问题...我正在发布答案,所以这可能对其他开发人员有所帮助...附言该项目是用 Yii 1.1 编写的

                  I have already resolved problem few month ago... I'm posting answer, so this might be helpful for other fellow developers... p.s. The project was written in Yii 1.1

                  首先,在我的 HorseController 中分配了私有数组类型变量,我将在其中保留谱系:

                  Firstly, in my HorseController assigned private array type variable where I am going to keep Pedigree:

                  private $horses = array();
                  

                  然后,我编写了从数据库中获取所有节点(父节点)的函数:

                  Then, I wrote function that will get all nodes (parents) from database:

                  public function getParents($id)
                  {
                      global $horses;
                      $horses[] = Horses::model()->findByPk($id)->horse_id;
                      if($this->loadModel($id)->horse_sire != null && $this->loadModel($id)->horse_dam != null)
                      {
                          $this->getParents($this->loadModel($id)->horse_sire);
                          $this->getParents($this->loadModel($id)->horse_dam);
                      }
                      return $horses;
                  }
                  

                  然后,我修改了 ActionView 函数,其中数据库中的所有节点都将传递给 View

                  Then, I modified ActionView function, where all nodes from database will be passed to View

                  public function actionView($id)
                  {
                      $this->horses = $this->getParents($id);
                      $this->render('view',array(
                          'model'=>$this->loadModel($id),
                          'parents'=>$this->horses,
                      ));
                  }
                  

                  最后是一些显示系谱的丑陋代码(例如系谱查询):)

                  And finally a bit of UGLY CODE that will show pedigree (like this Pedigree Query) :)

                  <table>
                              <?php
                                  $reverse_multiplier = (count($parents)+1)/2;
                                  $last_node_count = 0;
                                  for($i = 0; $i < count($parents); $i++)
                                  {
                                      if($i == 0 && $last_node_count ==1)
                                          echo "<tr>";
                  
                                      echo "<td rowspan='$reverse_multiplier'>";
                  
                                      echo "<a href=".Yii::app()->baseUrl."/index.php/horses/".Horses::model()->model()->findByPk($parents[$i])->horse_id." >";
                                      echo Horses::model()->model()->findByPk($parents[$i])->horse_name;
                                      echo "</a>";
                                      echo "<br/>";
                                      echo Horses::model()->model()->findByPk($parents[$i])->horse_yob;
                  
                                      echo "</td>";
                                      if($reverse_multiplier == 1 || $reverse_multiplier == 0.5)
                                          echo "</tr>";
                  
                                      if($reverse_multiplier == 0.5 && $last_node_count <= (count($parents)+1)/4)
                                          $reverse_multiplier = (count($parents)+1)/8;
                                      else
                                          $reverse_multiplier = $reverse_multiplier/2;
                  
                                      if($last_node_count == (count($parents)+1)/4)
                                      {
                                          $reverse_multiplier = (count($parents)+1)/4;
                                          $last_node_count=0;
                                      }
                                      if($reverse_multiplier == 0.5 || $reverse_multiplier == 1)
                                          $last_node_count++;
                                  }
                              ?>
                          </table>
                  

                  就是这样:)希望它有帮助...

                  And that's it :) Hope it was helpful...

                  这篇关于来自数据库的系谱/家谱图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Zend_Controller_Router_Exception:“xyz";未指定 下一篇:PHP:拆分字符串

                  相关文章

                  最新文章

                  <i id='MRUg2'><tr id='MRUg2'><dt id='MRUg2'><q id='MRUg2'><span id='MRUg2'><b id='MRUg2'><form id='MRUg2'><ins id='MRUg2'></ins><ul id='MRUg2'></ul><sub id='MRUg2'></sub></form><legend id='MRUg2'></legend><bdo id='MRUg2'><pre id='MRUg2'><center id='MRUg2'></center></pre></bdo></b><th id='MRUg2'></th></span></q></dt></tr></i><div id='MRUg2'><tfoot id='MRUg2'></tfoot><dl id='MRUg2'><fieldset id='MRUg2'></fieldset></dl></div>

                    • <bdo id='MRUg2'></bdo><ul id='MRUg2'></ul>

                    <tfoot id='MRUg2'></tfoot>
                    <legend id='MRUg2'><style id='MRUg2'><dir id='MRUg2'><q id='MRUg2'></q></dir></style></legend>

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