WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : a function that builds an HTML select list from any mysql table.
Categories : PHP, MySQL, HTML and PHP Update Picture
Chris Brown
Date : Aug 04th 2000
Grade : 3 of 5 (graded 14 times)
Viewed : 44769
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Chris Brown
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
/* Created by: Chris Brown
Date: 2000-AUG-04

This function will return an HTML select list from two columns in any table.
You have the option of specifying an "other" value wich is useful for null values on
data entry and an "All" option for queries. Also you can specify a default selected
item and a where clause to limit the records in the list.

Feel free to add to this and repost it or comment if you like, it needs some error
handling.

*/


function html_drop_down ($in_name
,$in_tablename
,$in_value_column_name
,$in_display_column_name
,$in_other_value = ""
,$in_other_display = ""
,$in_selected_value = ""
,$in_where_clause = "") {

// build the SQL string
$sql = "SELECT " . $in_value_column_name . " col_val," .
$in_display_column_name . " col_disp" .
" FROM " . $in_tablename;
if ($in_where_clause) {
$sql .= " " . $in_where_clause;
}
$sql .= " order by col_disp";

// connect to mysql, put your specifics here.
mysql_pconnect() or die ("problems connecting to Database.");

// queries the database, be sure to name your database.
$result = mysql_db_query("ecomm",$sql);

// build the select list.
if ($result) {
$return_value = "<SELECT NAME=\"$in_name\">";

if ($in_other_display) {
$return_value .= "<OPTION VALUE=\"$in_other_value\"> $in_other_display </OPTION>";
}

while ($rec = mysql_fetch_array($result)) {

$return_value .= "<OPTION ";

if ($in_selected_value) {
if ($rec["col_val"] == $in_selected_value) {
$return_value .= " SELECTED ";
}
}

$return_value .= " VALUE=\"" . $rec["col_val"] . "\"> " .
$rec["col_disp"] . " </OPTION>";
}

$return_value .= "</select>";
} else {
$return_value .= "No data.";
}

mysql_free_result($result);

return $return_value;

}
?>

<?
/* Here's three examples of how you can use this function */

/* Simple example */
echo html_drop_down ("formvar1_prod_type"
,"prod_types"
,"prod_type_id"
,"name");

/* An example with an extra value in the list, good for N/A, All values for queries etc.. */
echo html_drop_down ("formvar2_prod_type"
,"prod_types"
,"prod_type_id"
,"name"
,"-1"
,"All Types");

/* An example with a where clause */
echo html_drop_down ("formvar3_prod_type"
,"prod_types"
,"prod_type_id"
,"name"
,"-1"
,"All Types"
,"3"
,"WHERE prod_type_id <> 4");


/* Here's the data used in my example, it should work with any table though:

mysql> select prod_type_id, name from prod_types;
+--------------+-------------------+
| prod_type_id | name |
+--------------+-------------------+
| 1 | Mother Boards |
| 2 | Graphics Cards |
| 3 | Memory |
| 4 | Pointing Devices |
| 5 | Keyboards |
| 6 | Operating Systems |
+--------------+-------------------+
6 rows in set (0.00 sec)

mysql>

*/

?>



PHP mySQL learning example This is a complete program to modify tables in a mySQL database on a nice and neat way.
Categories : PHP, MySQL, Complete Programs, HTML and PHP
Random quote generator using MySQL and PHP. Allows HTML tags inside quotes and features a marker so a sigle quote will not be repeated after consecutive page loads.
Categories : PHP, HTML and PHP, MySQL
Complete, simple working example of login screen and check on a unique page using php functions, cookies and mysql database.
Categories : PHP, Cookies, MySQL, HTML and PHP, Authentication
dynamic table columns
Categories : PHP, HTML and PHP, Arrays, Databases, MySQL
Amazon book cover handling
Categories : HTML and PHP, PHP, MySQL, Ecommerce
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
Complex paging with no resultset limit
Categories : PHP, MySQL, Databases, Output Control, HTML and PHP
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
Pull Down Surfing - Surf on Change
Categories : Java Script, MySQL, HTML and PHP, PHP, Databases
Functions for loading images into a MySQL database and displaying them.
Categories : Graphics, HTML and PHP, MySQL, PHP, Databases
Message of the Day - Random Message (Needs MySQL!)
Categories : Databases, HTML and PHP, PHP, MySQL
Required form fields that pull from MySQL database
Categories : PHP, HTML and PHP, Databases, MySQL
Dynamically generated pop-ups (Select items)
Categories : PHP, HTML and PHP, MySQL, Databases
Php and Mysql Authentication using cookies
Categories : PHP, MySQL, HTML and PHP
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases