|
|
|
|
|
|
| |
This small function is used to build a select menu with the values from a database table. Create the SQL statement outside the function with two values, one for the (option) value and one for the (option) label. The function is completely dynamic, you can change the name for the html elements (label and select) and you can use all tables you like.
| <?php
// example sql statement
$sql = "SELECT col_for_value, col_for_label FROM some_table";
function database_select($tbl_value, $tbl_label, $select_name, $label) {
global $sql;
$result = mysql_query($sql);
$menu = "<label for=\"".$select_name."\">".$label."</label>\n";
$menu .= "<select name=\"".$select_name."\">\n";
$menu .= " <option value=\"\"";
$menu .= (!isset($_REQUEST[$select_name])) ? " selected" : "";
$menu .= ">...\n";
while ($obj = mysql_fetch_object($result)) {
$menu .= " <option value=\"".$obj->$tbl_value."\"";
$menu .= (isset($_REQUEST[$select_name]) && $obj->$tbl_value == $_REQUEST[$select_name]) ? " selected" : "";
$menu .= ">".$obj->$tbl_label."\n";
}
$menu .= "</select>\n";
mysql_free_result($result);
return $menu;
}
// example:
// use the col names from the table too...
echo database_select("col_for_value", "col_for_label", "my_select", "Select from:");
/* example output
<label for="my_select">Select from:</label>
<select name="my_select">
<option value="" selected>...
<option value="val_1">value 1
<option value="val_2">value 2
...
</select>
*/
?> | | |
|
| PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | | | PHP template processing Categories : PHP, Templates, HTML and PHP | | | XDT Topsite (Gold v1.0) Categories : Databases, CSS, PHP, HTML and PHP, Sessions | | | function textwrap will wrap text to any desired width using <BR>\n as the default line break.
Default wrap width is 80 columns.
Categories : Strings, HTML and PHP, PHP | |
|
|
|