Before you start make sure you already know what it is php and mysql databases. because that will be discussed here is a tutorial to create a “Drop Down List Box” by using php and mysql. so we will not discuss things that are as basic as installing a webserver or php itself. OK let us start…

1. Create Database Test

for creating database you can use syntax : create database test;

in phpmyadmin or mysql interface icon wink Tutorial a Drop Down List Box Using PHP & MYSQL

2. Create Tbale Name

for creating table in database Test you can use syntax :

use test;

create table names
( ID integer auto_increment,
name varchar(30),
primary key (yearID)
);

insert into nemes (ID, name) values (’0′, ‘name1′);
insert into nemes (ID, name) values (’0′, ‘name2′);
insert into nemes (ID, name) values (’0′, ‘name3′);
insert into nemes (ID, name) values (’0′, ‘name4′);
insert into nemes (ID, name) values (’0′, ‘name5′);
insert into nemes (yearID, year) values (’0′, ’2012-2013′);

3. PHP Code

The following PHP script (list.php), which would form part of a form, will extract all the entries from the ‘names’ database table, and use them to populate the drop down list box.

List.php

<?php

$data = @mysql_query(“select * from names”);
echo “<p>Select a Name: n”;
echo “<Select Name=”ID”>n”;
while ($row = mysql_fetch_assoc($data))
{
$ID = $row['ID'];
$year = $row['name'];
echo “<option value=$ID>$namen”;
}
echo “</select>n”;
echo “</p>n”;
?>

i hope this article usefull icon wink Tutorial a Drop Down List Box Using PHP & MYSQL

Incoming search terms for the article:

Related Post:

Tagged with:

Filed under: PHP

Like this post? Subscribe to my RSS feed and get loads more!