RE: [PHP-DB] Populating a combo box from a mssql server

From: Date: Fri, 18 Aug 2000 11:39:14 +0000
Subject: RE: [PHP-DB] Populating a combo box from a mssql server
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-2151@lists.php.net to get a copy of this message
A, maybe this is usefull : /* Function to create a combo box, usage : MakeSelectBox (<SelectionBoxName>,<TableName>,<KeyField>,<ShowedField>,<Option toggle>,<default index>,<WhereStatment>)*/ function MakeSelectBox ( $SelectName, $TableName, $KeyField, $ShowField, $AnyOption = 0, $DefaultID="", $WhereStatmnt="") { global $dbserver, $username, $password, $database; mssql_connect($dbserver,$username,$password) or die("Database is down"); mssql_select_db($database) or die("Database is down"); $query = "SELECT * FROM $TableName $WhereStatmnt order by $ShowField"; $results = mssql_query($query) or die("Query failed"); printf("<select name=\"$SelectName\">\n"); if ($AnyOption == 1) { printf("<option \"\">Any\n"); } while ($row = mssql_fetch_array($results)): $id = $row["$KeyField"]; $name = $row["$ShowField"]; if ($id == $DefaultID) { printf("<option SELECTED value=\"$id\">$name\n"); } else { printf("<option value=\"$id\">$name\n"); } endwhile; mssql_close(); printf("</select>\n"); } Hope you guys can use it ;) Best regards, Jeroen. -----Original Message----- From: Jeroen ten Berge [mailto:j.ten.berge@getexo.nl] Sent: Friday, August 18, 2000 11:20 To: php-db@lists.php.net Subject: [PHP-DB] Populating a combo box from a mssql server Does anyone have an example for me how to populate a combobox from a mssql table ? I need the following functionality : Value=primary key from a table, displayed text is a field from that table... Thanks in advance, Jeroen. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#2151) next »