WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 widget for presenting color options in a drop down menu
Categories : HTML, PHP Update Picture
Paul Meagher
Date : Jan 17th 1999
Grade : 2 of 5 (graded 6 times)
Viewed : 5413
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Paul Meagher
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<HTML>
<TITLE>Color Selector Widget</TITLE>
<BODY>

<?

/*
Script Name: color_drop.html

Script Purpose: A widget for presenting color options in
a drop down menu.

Script Author: Paul D. Meagher (meagher@mallnetglobal.com).

Copyright: Open Source Freeware.

Demo: http://www.mallnetglobal.com/colors/color_drop.html

Script Setup: This script draws color information
(color name, color code) from a MySQL database and presents
it to the user as a drop down menu of color terms.
There are many situations in which you will want to allow
people to control the color of some object by selecting its
color. In this example, I want to allow the person
to control the color of text.

You will need to create a database and insert color names
and associated rgb values into it. I have developed a php3
script that facilitates entry of new color terms and values,
but it is not yet ready for release. This might be overkill
as it is probably easier to load a text file of mysql inserts.

Here is the table schema that I am using.

CREATE TABLE colors (
uid MEDIUMINT(8) NOT NULL AUTO_INCREMENT,
color_name VARCHAR(50),
color_code VARCHAR(10),
PRIMARY KEY(uid)
);

The program also maintains state information about the color
previously selected. If this program is passed the variable
text_color, it will present its value as the currently selected
item in the drop down box.

*/

/* Declare some variables. */

$hostname = "localhost";
$password = "";
$user = "ftp";
$database = "colors_db";
$table = "colors";

/* Main Loop */

echo "The text will look link this <font color=\"$text_color\">Sample</font> <br>";

mysql_connect($hosthame,$user,$password);
$result = mysql($database, "SELECT distinct color_name,color_code FROM $table ORDER BY color_name");
$num_cols = mysql_numrows($result);
$counter = 0;
echo "<FORM METHOD = \"POST\" ACTION=\"color_drop.html\">\n";
echo "<select name=\"text_color\">\n";
if ($text_color == "") {
echo "<option selected>Select Color...\n" ;
};
while($counter < $num_cols):
$cn = @mysql_result($result,$counter, "color_name");
$cc = @mysql_result($result,$counter, "color_code");
if ($text_color == $cc) {
echo "<option value=\"$cc\" selected>$cn\n" ;
} else {
echo "<option value=\"$cc\">$cn\n" ;
};
$counter = $counter + 1;
endwhile;
echo "</select>\n";
echo "<INPUT TYPE=\"submit\" VALUE=\"View Color\">\n";
echo "</FORM>\n";
?>
</BODY>
</HTML>



Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
How to know which input button of type image was pressed in a form with multiple image buttons (_x and _y) in PHP?
Categories : PHP, Variables, HTML
How to preset a text string in a textarea input field
Categories : HTML, HTML and PHP, PHP, Beginner Guides
Paginator - a class that can help you to split MySQL database query result sets to pages.
Categories : MySQL, Databases, HTML, PHP
How to use regular expressions to get the list of links from an HTML page
Categories : PHP, Regexps, HTML, HTML and PHP
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Browser Detecor Class
Categories : PHP Classes, PHP, HTML
GonxTabs : Create elegant HTML tabs based interface
Categories : Navigation, HTML, HTML and PHP, PHP
Real simple example of removing HTML tags from text then changing \n (new line) to <br>. Could be used in a forum for instance.
Categories : HTML, PHP, HTML and PHP, Beginner Guides
How to get the source of a site into an array.
Categories : Arrays, HTML, PHP
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
Display Slashdot headers on your own site
Categories : HTML and PHP, HTML, PHP
Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a
Categories : HTML, PHP, PHP Classes, Regexps
Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but effective.
Categories : PHP, PHP Classes, HTML, HTML and PHP
class formHTML build your HTML Forms from PHP
Categories : PHP, PHP Classes, HTML and PHP, HTML