RE: [PHP] modifying drop-downs

From: Date: Tue, 15 Aug 2000 20:17:26 +0000
Subject: RE: [PHP] modifying drop-downs
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-11871@lists.php.net to get a copy of this message
I use this function: function ListboxMatch ($size, $name, $query, $matchtothis) { $qry = mysql_db_query("database",$query); if (mysql_num_rows($qry) > 0) { echo "<SELECT SIZE='".$size."' NAME='".$name."'>\n\t<OPTION VALUE=''>\n"; while (list($value, $text) = mysql_fetch_row($qry)) { echo "\t<OPTION VALUE='".$value."'"; if ($value == $matchtothis) { echo " SELECTED"; } echo ">".$text."\n"; } echo "</SELECT>"; } else echo "No data in listbox\n"; mysql_free_result($qry); } /* end ListboxMatch */ then call it like so (so it has exactly two columns it returns in each query): <?php ListboxMatch(1, "edit_subcategory_id", "SELECT subcategory_id, subcategory_name FROM SubCategory_Table ORDER BY subcategory_name", $edit_subcategory_id); ?> > -----Original Message----- > From: root@inetarena.com [mailto:root@inetarena.com]On Behalf Of curt666 > Sent: Sunday, August 13, 2000 8:01 PM > To: PHP-general > Subject: [PHP] modifying drop-downs > > > Hi all, > > I'm having trouble pulling data from a query result into the drop-downs > on the add/modify form. The form is a mix of fill-in CHAR columns and > ENUM columns. Add works, the row data returned from the query is right, > but the drop-downs reflect the initial value in ENUM and OPTION VALUE, > not the actual row info (the CHAR columns populate properly). > > It's a books database, and the add books form has, along with TITLE and > ISBN, drop-downs like BINDING > ENUM('paperback','tradepaper','hardcover'), which seem the most > sensible > type for this. Have I set this up incorrectly? > > Using PHP 4.0.1pl2, MySQL 3.22.32, SuSE 6.4 > > Code samples follow... > > <? > > # ------------------ > # BLcommon.php > # common functions > # ------------------ > > ... > > # --------------------------------------------------- > # generate the HTML form to add/change/delete BOOKS > # --------------------------------------------------- > > function generateHTMLform($formvalues, $actionscript, $submitlabel) > { > printf("<FORM METHOD=post ACTION=\"%s\"><PRE>\n", > $actionscript); > > # -------------- > # start fill-ins > # -------------- > > printf("&nbsp;&nbsp;"); > printf("<FONT SIZE=3 > FACE=helvetica>Title > Publisher YrPub"); > printf("<BR>"); > printf("&nbsp;&nbsp;&nbsp;"); > printf("<INPUT TYPE=text SIZE=20 NAME=title VALUE=\"%s\">", > ($formvalues) ? $formvalues["title"] : ""); > printf("&nbsp;&nbsp;&nbsp;&nbsp;"); > printf("<INPUT TYPE=text SIZE=20 NAME=publisher VALUE=\"%s\">", > ($formvalues) ? $formvalues["publisher"] : ""); > printf("&nbsp;&nbsp;&nbsp;&nbsp;"); > printf("<INPUT TYPE=text SIZE=4 NAME=yearpub VALUE=\"%s\">", > ($formvalues) ? $formvalues["yearpub"] : ""); > printf("<BR>\n"); > printf("<BR>\n"); > printf("&nbsp;&nbsp;&nbsp;"); > > ... > > # ---------------- > # start drop-downs > # ---------------- > > printf("<FONT SIZE=3 FACE=helvetica> Category > Binding First ed? Signed?"); > printf("<BR>"); > printf("&nbsp;&nbsp;&nbsp;"); > > printf("<SELECT NAME=category>", ($formvalues) ? > $formvalues["category"] > : ""); > printf("<OPTION VALUE=literature>literature", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=fiction>fiction", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=non_fiction>non-fiction", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=humor>humor", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=history>history", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=hist_fiction>hist. fiction", ($formvalues) ? > $formvalues["category"] : ""); > printf("<OPTION VALUE=science>science", ($formvalues) ? > $formvalues["category"] : ""); > printf("</SELECT>"); > printf("&nbsp;&nbsp;&nbsp;"); > > printf("<SELECT NAME=binding>", ($formvalues) ? > $formvalues["binding"] : > ""); > printf("<OPTION VALUE=paperback>paperback", ($formvalues) ? > $formvalues["binding"] : ""); > printf("<OPTION VALUE=tradepaper>trade paper", ($formvalues) ? > $formvalues["binding"] : ""); > printf("<OPTION VALUE=hardcover>hardcover", ($formvalues) ? > $formvalues["binding"] : ""); > printf("</SELECT>"); > > ... > > printf("<INPUT TYPE=submit VALUE=\"%s\">", $submitlabel ); > printf("</PRE></FORM>" ); > } > > function returntomain() > { > printf("<FORM ACTION=\"BLmain.php\" METHOD=post>\n"); > printf("<B><FONT COLOR=\"#42426F\"><INPUT TYPE=submit > VALUE=\" back to > main page \"></B>\n"); > printf("&nbsp; &nbsp; &nbsp;"); > } > > > > ?> > > > -------------------------------------------------- > > > <? > > #------------------- > # BLchange-book.php > #------------------- > > require("BLglobals.php") ; > require("BLcommon.php") ; > > $selectstmt = "SELECT * FROM books WHERE bookid=$bookid" ; > > #--------------- > # connect to db > #--------------- > > if (!($link=mysql_pconnect ($host, $user, $password))) > { > displayerrmsg(sprintf("error connecting to host %s, by user > %s",$host, $user)) ; > exit() ; > } > > #----------- > # select db > #----------- > > if (!mysql_select_db($dbname, $link)) > { > displayerrmsg(sprintf("Error in selecting %s > database", $dbname)) ; > displayerrmsg(sprintf("error:%d %s", mysql_errno($link), > mysql_error($link))) ; > exit() ; > } > > #------------------- > # execute the query > #------------------- > > if (!($result= mysql_query($selectstmt, $link))) > { > displayerrmsg(sprintf("Error in executing %s stmt", > $selectstmt)) ; > displayerrmsg(sprintf("error:%d %s", mysql_errno($link), > mysql_error($link))) ; > exit() ; > } > > generateHTMLheader( "please make any desired changes...") ; > > if (!($row = mysql_fetch_object($result))) > { > displayerrmsg("Internal error: the entry does not exist") ; > exit() ; > } > > $resultentry["bookid"] = $row->bookid; > $resultentry["title"] = $row->title; > $resultentry["publisher"]= $row->publisher; > $resultentry["yearpub"]= $row->yearpub; > $resultentry["isbn"]= $row->isbn; > $resultentry["yearpurch"]= $row->yearpurch; > $resultentry["pricepaid"]= $row->pricepaid; > $resultentry["comments"]= $row->comments; > $resultentry["category"]= $row->category; > $resultentry["binding"]= $row->binding; > $resultentry["first_ed"]= $row->first_ed; > $resultentry["signed"]= $row->signed; > $resultentry["bookcondition"]= $row->bookcondition; > $resultentry["dj_condition"]= $row->dj_condition; > > generateHTMLform( $resultentry, > "BLupdate-book.php?bookid=$bookid", " > submit changes... " ); > > mysql_free_result($result) ; > ?> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#11871) next »