+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP Multilevel drop down generator class

  1. #1
    Slothie's Avatar
    Slothie is offline Lord Of The Keys Slothie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    PHP Multilevel drop down generator class

    PHP Code:
    <?php
    //sample usage
    $drop = new dropper();
    $drop->tab = ( '--' );
    $drop->generate_drop();
    echo 
    $drop->output;
    //end sample

    class dropper
    {
        public 
    $dbhost;
        public 
    $dbuser;
        public 
    $dbpass;
        public 
    $dbname;
        public 
    $table;
        public 
    $parent ;
        public 
    $desc;
        public 
    $id;
        public 
    $tab;
        private 
    $tablvl;
        public 
    $output;

        function 
    __construct()
        {
            
    $this->dbhost "localhost";
            
    $this->dbuser "root";
            
    $this->dbpass "changeme";
            
    $this->dbname "dbame"
            
    $this->table "tablename";
            
    $this->parent "parent";
            
    $this->desc "desc";
            
    $this->id "primarykey";
            
    $this->tablvl 0;
            
    $this->output '';
            
    $this->filler "";
        } 

        function 
    generate_drop()
        {
            
    $link mysql_connect$this->dbhost$this->dbuser$this->dbpass );
            
    mysql_select_db$this->dbname );
            
    $res mysql_query"select count(*)  FROM  " $this->table );
            
    $numros mysql_fetch_array$res );
            
    $numrows $numros[0];
            
    $this->output .= ( "<select  name=\"hierarchy\" >\n" );
            
    $this->output .= ( "<option  value=\"null\"  selected=\"selected\">" $this->filler "</option>\n" );
            
    $this->print_kids'' );
            
    $this->output .= ( "</select>" );
            @
    mysql_close$link );
        } 

        function 
    print_kids$pos '' )
        {
            
    $link mysql_connect$this->dbhost$this->dbuser$this->dbpass );
            
    mysql_select_db$this->dbname );
            
    $query "Select " $this->id "," $this->desc "," $this->parent " from " $this->table " where " $this->parent;
            if ( 
    $pos == '' )
            {
                
    $query .= " IS NULL";
            } 
            else
            {
                
    $query .= " = $pos";
            } 

            
    $res mysql_query$query );

            while ( 
    $row mysql_fetch_array$res ) )
            {
                
    $q "Select count(*) from " $this->table " where " $this->parent "=" $row[0] ;

                
    $x mysql_query $q );

                
    $hk mysql_fetch_array$x );
                
    $this->output .= ( "<option  value=\"$row[0]\">" );
                for ( 
    $i 0$i $this->tablvl$i++ ) $this->output .= ( $this->tab );
                
    $this->output .= ( "$row[1]</option>\n" );

                if ( 
    $hk[0] > )
                {
                    
    $this->tablvl++; 
                    
    // echo $row[0]."!!!!";
                    
    $this->print_kids$row[0] );
                } 
            } 
            
    $this->tablvl--;
            @
    mysql_close$link2 );
        } 


    ?>
    Notes:
    • This is a PHP5-Only class (Although it should be easily modifiable to php4)
    • All public class variables are modifiable from outside
    Just reply here if you have any questions, and as usual... rep me if ya find this useful.
    Last edited by Slothie; 10-19-2007 at 01:46 AM.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  2. #2
    majid786 is offline x10Hosting Member majid786 is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    4

    Re: PHP Multilevel drop down generator class

    thanx man

  3. #3
    tobyb is offline x10Hosting Member tobyb is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    7

    Re: PHP Multilevel drop down generator class

    thankx i have been trying to get this to work all night got it to work now

  4. #4
    DarkDragonLord's Avatar
    DarkDragonLord is offline x10 Elder DarkDragonLord is an unknown quantity at this point
    Join Date
    Mar 2007
    Location
    Brazil
    Posts
    782

    Re: PHP Multilevel drop down generator class

    too bad i have no idea what this makes
    im still at basics of PHP lol XD
    would you mind adding a demo or explaining to a newbie what it makes?
    Regards,
    Raphael DDL

    Designing Solutions for You
    *Web Design;
    *Coding;
    Free Downloads;
    and all related Stuff
    .


    My Tutorials:
    | Multi-Language Websites | Rotative Banners |
    | Bookmark Script for All Browsers
    |
    |
    PHP Switching/Including Content|
    |


  5. #5
    php2lthands is offline x10Hosting Member php2lthands is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    1

    Re: PHP Multilevel drop down generator class

    Am trying to get dropdown to work
    public $dbhost; //ok
    public $dbuser; // ok
    public $dbpass; // ok
    public $dbname; // ok
    public $table; // ok
    public $parent ; // is this a field from the table?
    public $desc; // ok
    public $id; // is the name of id field to put here - for reasons best known to me my primary key is PVMS
    public $tab; // presume required by function leave empty
    private $tablvl;// presume required by function leave empty
    public $output; // presume required by function leave empty

    help me sleep please.
    Last edited by php2lthands; 04-27-2011 at 09:19 PM.

+ Reply to Thread

Similar Threads

  1. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  2. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers