I'm having a bit of a problem with the following classes.

Class pulldown builds a select box using a set of arrays containing 
the relevant data.

class pulldown_db is written to extend the class to allow the use of 
the class with a database.

Now, the problem appears in pulldown_db.  If you notice the code at 
the end which tests the objects, $dbpul never seems to get created.

I'm rather puzzled as to why this should be.

// Select box building classes written by Steve Dix Feb 2002.
// These are replacements for the functions "pulldown_array" and 
// They are not DIRECT replacements, having different parameters.
// Please see the bottom for examples of how to initialise and use 
the classes.
// New input string should be :
//      array(control), array(ausgabe[ausgabe|wert|zieldatei]
//      Control array should be enumerated.

// Class to build and display a selection box for use in a form from 
a supplied array.
class pulldown
        var $ausgabe=array();
        var $control=array();

        var $mehrfach;
        var $onchange_text;
        var $class_text;
        var $size_text;

        // constructor for class copies supplied arrays - control containing 
control information, ausgabe containing data
        // then calls the private method build_list() to sort out internal 
flags based on the control array.
        // note that the control array makes use of associative indexes to 
make the source more self-documenting.

        function pulldown($control,$ausgabe)
                global $DEBUG;

                echo "Initialise<br>\n";

                        if($DEBUG) echo "$key,$data<br>\n";

                                $this->ausgabe[$key][$k] = $d;
                                if($DEBUG) echo "$key $k $d<br>\n";

                // Mehrfach-Auswahl


        // public method write - writes the complete html select code
        function output_select()
                // Pulldown bauen
                echo "$text\n";
                echo "<select name='".$this->control[name]."'".$this-
                // Auswahl
                $cnt = count($this->ausgabe[ausgabe]);

                if(DEBUG) echo "cnt $cnt<br>\n";
                        // Selektieren
                                $select = "selected";
                        if($this->ausgabe[wert][$i]!="0" && !empty($this-
                                $wert = $this->ausgabe[wert][$i];
                                $wert = $this->ausgabe[ausgabe][$i];
                        echo "<option value='$wert' $select>".$this-
                echo "</select>\n";

        // build_list - private method to set various variables according to 
the control array.
        function build_list()
                $this->mehrfach = ($this->control[mehrfach]=="1") ? ' multiple' 
: '';

                $this->onchange_text = ($this->control[onchange]!="" && $this-
                        ? " onChange='".$onchange."' " 
                        : "";

                $this->class_text = ($this->control["class"] != "") 
                        ? "class='".$this->control["class"]."' " 
                        : "";

                $this->size_text = ($this->control[size]!="") 
                        ? "size='".$this->control[size]."' "
                        : "";

// class pulldown_database extends the above class to deal with 
// it deliberately makes use of inheritance so that you can still use 
the ausgabe array to add
// options which cannot be found in the database.

class pulldown_db extends pulldown
        // private method used to set control info based on control
        function build_list()


                echo "<br>build list<br>\n";
                // now we can extend the ausgabe array by using the extra item 
"query" which should be included in the control array.

                $qu = mysql_query($this->control[query]);
                $cnt = @mysql_numrows($qu);

                echo $this->control[query]." cnt $cnt<br>\n";

                        list($this,$that) = mysql_fetch_row($qu);
                        echo "this $this that $that<br>\n";

// Example pulldown array - uncomment to see how it works.
$pull = new pulldown(
                array("name"=>"test", "size"=>"", "text"=>"A test select", 
"mehrfach"=>"", "selektiert"=>"", "onchange"=>"", "class"=>"" ),
                array( "ausgabe"=>array("moo","quack","baa","woof"), 
"wert"=>array(1,2,3,4) )


// here you connect to the db - pconnect removed for security

$dbpul = new pulldown_db(
                array("query"=>"select id,medientyp from 
medientyp","name"=>"database", "size"=>"", "text"=>"Another test 
select", "mehrfach"=>"", "selektiert"=>"", "onchange"=>"", 
                array("ausgabe"=>array("--"), "wert"=>array(0))

        echo "Fail $dbpul<br>\n";

?>Steve Dix>==============================<[EMAIL PROTECTED]

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

Reply via email to