MySQL Database Php


Color Selector Widget

/*
Script Name: color_drop.html
Script Purpose: A widget for presenting color options in
a drop down menu.
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.
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 = "";
$password = "";
$user = "";
$database = "colors_db";
$table = "colors";
/* Main Loop */
echo "The text will look link this Sample

";
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 "
\n";
echo "\n";
echo "\n";
echo "
\n";
?>