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 "pulldown_database" // 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"; while(list($key,$data)=each($control)) { $this->control[$key]=$data; if($DEBUG) echo "$key,$data<br>\n"; } while(list($key,$data)=each($ausgabe)) { while(list($k,$d)=each($data)) { $this->ausgabe[$key][$k] = $d; if($DEBUG) echo "$key $k $d<br>\n"; } } // Mehrfach-Auswahl $this->build_list(); } // public method write - writes the complete html select code function output_select() { // Pulldown bauen echo "$text\n"; echo "<select name='".$this->control[name]."'".$this- >onchange_text.$this->size_text.$this->class_text.$mehrfach.">\n"; // Auswahl $cnt = count($this->ausgabe[ausgabe]); if(DEBUG) echo "cnt $cnt<br>\n"; for($i=0;$i<$cnt;$i++) { // Selektieren if($this->ausgabe[ausgabe][$i]==$this->control[selektiert]) { $select = "selected"; } else { $select=""; } if($this->ausgabe[wert][$i]!="0" && !empty($this- >ausgabe[wert][$i])) { $wert = $this->ausgabe[wert][$i]; } else { $wert = $this->ausgabe[ausgabe][$i]; } echo "<option value='$wert' $select>".$this- >ausgabe[ausgabe][$i]."</option>\n"; } 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- >control[onchange]!="0") ? " 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 databases // 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() { pulldown::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"; for($i=0;$i<$cnt;$i++) { list($this,$that) = mysql_fetch_row($qu); echo "this $this that $that<br>\n"; $this->ausgabe[ausgabe][]=$this; $this->ausgabe[wert][]=$that; } } } // 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) ) ); $pull->output_select(); // 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"=>"", "class"=>""), array("ausgabe"=>array("--"), "wert"=>array(0)) ); if(is_object($dbpul)) { $dbpul->output_select(); } else echo "Fail $dbpul<br>\n"; ?>Steve Dix>==============================<[EMAIL PROTECTED] http://www.stevedix.de/ http://www.snorty.net/ http://www.mp3.com/simpletons http://www.geocities.com/motorcity/2706 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php