RE: Class function calling another function in class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You might find this interesting if you are working with hierarchies in
SQL

http://www.intelligententerprise.com/001020/celko.jhtml?_requestid=72430
3

-----Original Message-----
From: Richard Lynch [mailto:ceo@xxxxxxxxx] 
Sent: 19 May 2005 07:35
To: Charles Kline
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Class function calling another function in class


On Wed, May 18, 2005 5:04 pm, Charles Kline said:
> I have an organization table in mySQL. Pretty standard. My first 
> function getDepts() is working as I intend and returning the tree just

> as I like it. The new piece I added in there that is not working now 
> is the call to getPositions() within the first function. What I am 
> trying to do is once I get a Department, I want to loop through the 
> Positions table and get the positions that are under that Department. 
> This code goes haywire and loops for ever printing a huge list to the 
> screen. Eventually I need to return this data not to the screen but 
> into an array. Anyone see what I might have wrong in my logic?

What is in the huge list?...

Actually...

If your organization and/or its budget positions is at all large, this
is an incredibly inefficient way to do it.

You're hammering your database with query after query, and you are using
PHP to do all the iteration and ordering.

SQL was *designed* to handle large amounts of data efficiently.

You would be better served with something not unlike:

$query = "select boOrgId, boOrgName, bpPositionID ";
$query .= " from BudgetedOrganization, BudgetedPosition "; $query .= "
where BudgetedOrganization.boOrgID = BudgetedPosition.bp_boOrgID ";
$query .= " order by boSuperiorOrgID "; $rs =
$this->retrieveData($query); if ($rs){
  while ($row = mysql_fetch_array($rs)){
    //Store $row in your array or whatever you want to do with it.
  }
}

> I have a class and it contains these two functions.
>
>      function getDepts ( $parent = 0, $level = 1 ) {
>          $sql = 'SELECT BudgetedOrganization.* ';
>          $sql .= 'FROM BudgetedOrganization ';
>          $sql .= 'WHERE BudgetedOrganization.boSuperiorOrgID = ' . 
> $parent;
>
>          $rs = $this->retrieveData($sql);
>          if ($rs)
>          {
>              while($row = mysql_fetch_array($rs)){
>                  $num = 1;
>
>                  while ($num <= $level) {
>                      $this->str .= "\t";
>                      $num++;
>                  }
>                  $this->str .= $row['boOrgID'] . ", " . $row 
> ['boOrgName'] . "\n";
>
>                 // just added this and it ain't working
>                  $this->str .= $this->getPositions($row['boOrgID']);
>                  $this->getDepts($row['boOrgID'],$level+1);
>              }
>          }
>          return($this->str);
>      }
>
>      function getPositions ( $org = 0 ) {
>          $sql = 'SELECT BudgetedPosition.* ';
>          $sql .= 'FROM BudgetedPosition ';
>          $sql .= 'WHERE BudgetedPosition.bp_boOrgID = ' . $org;
>          //echo $sql;
>          $rs = $this->retrieveData($sql);
>          if ($rs)
>          {
>              while($row = mysql_fetch_array($rs)){
>                  $this->str .= " - " . $row['bpPositionID'] . "\n";
>              }
>          }
>          return($this->str);
>      }
>
>
> Later....
>
> $depts = $org->getDepts();
> echo "<pre>" . $depts . "</pre>";
>
>
> Thanks,
> Charles
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Gamma Global : Suppliers of HPCompaq, IBM, Acer, EPI, APC, Cyclades, D-Link, Cisco, Sun Microsystems, 3Com

GAMMA GLOBAL (UK) LTD IS A RECOGNISED 'INVESTOR IN PEOPLE' AND AN 'ISO 9001 2000' REGISTERED COMPANY

**********************************************************************

CONFIDENTIALITY NOTICE:

This Email is confidential and may also be privileged. If you are not the
intended recipient, please notify the sender IMMEDIATELY; you should not
copy the email or use it for any purpose or disclose its contents to any
other person.

GENERAL STATEMENT:

Any statements made, or intentions expressed in this communication may not
necessarily reflect the view of Gamma Global (UK) Ltd. Be advised that no content
herein may be held binding upon Gamma Global (UK) Ltd or any associated company
unless confirmed by the issuance of a formal contractual document or
Purchase Order,  subject to our Terms and Conditions available from http://www.gammaglobal.com

E&OE

**********************************************************************
**********************************************************************


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux