OOP: Function in a Function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

OOP: Function in a Function

Post by psurrena »

I have a loop nested in a loop in order to create columns and rows in a table. I'm turning the code below into a class.
I want to turn both the row and the column loop into their own, separate, functions. So, my questions is, in a class, how do you call one function from inside another?

Code: Select all

 
while(list($l_id,$l_name)=mysql_fetch_array($rowResult)){
    $row.= "<tr valign=\"top\">\n";
    $row.= "<td width=\"20%\">Level $l_name</td>\n";
        $colQuery="SELECT d_id, d_name FROM discipline ";
        if($discipline!=NULL){
            $colQuery.="WHERE d_id=$discipline ";
        }
        $colQuery.="ORDER BY d_id ASC";
        $colResult=mysql_query($colQuery) or die ("<strong>Level Error:</strong> ".mysql_error());
 
        while(list($d_id,$d_discipline)=mysql_fetch_array($colResult)){
                $row.= "<td class=\"inside\">\n";
                $empQuery="SELECT e_id, e_fname, e_lname, e_performance FROM employee ";
                $empQuery.="WHERE e_discipline=$d_id AND e_level=$l_id ";
 
                if($office != NULL){
                    $empQuery.="AND e_office=$office ";
                }
                $empQuery.="ORDER BY e_performance,e_title,e_lname ASC";
                $empResult=mysql_query($empQuery) or die ("<strong>Employee Error:</strong> ".mysql_error());
                while(list($e_id,$fname, $lname,$e_performance)=mysql_fetch_array($empResult)){
                    $row.= " <a class=\"info\" href=\"index.php?page=profile&id=$e_id\"><img title=\"{$fname} {$lname}\" src=\"images/rating/$e_performance.png\" /></a> ";
                }
        }
}
 
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: OOP: Function in a Function

Post by John Cartwright »

Code: Select all

class foo {
   function foo1() {
      $this->foo2();
   }
 
   function foo2() {
      echo 'foo2';
   }
}
 
$foo = new foo();
echo $foo->foo1(); //outputs foo2
:?:
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Re: OOP: Function in a Function

Post by psurrena »

so simple, thanks!
Post Reply