Steps:
create a database ‘test’.
create a table inside test using the below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
CREATE TABLE IF NOT EXISTS `tbl_city` ( `id` int(11) NOT NULL AUTO_INCREMENT, `city_name` varchar(255) NOT NULL, `state_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=51 ; -- -- Dumping data for table `tbl_city` -- INSERT INTO `tbl_city` (`id`, `city_name`, `state_id`) VALUES (1, 'Kolkata', 1), (2, 'Asansol', 1), (3, 'Siliguri', 1), (4, 'Durgapur', 1), (5, 'Bardhaman', 1), (6, 'Dankuni', 1), (7, 'Ajmer', 2), (8, 'Bikaner', 2), (9, 'Jaipur', 2), (10, 'Udaipur', 2), (11, 'Shimla', 3), (12, 'Mumbai ', 4), (13, 'Pune', 4), (14, 'Nagpur', 4), (15, 'Thane', 4), (16, 'Solapur', 4), (17, 'Bhiwandi', 4), (18, 'Amravati', 4), (19, 'Nashik', 4), (20, 'Melbourne', 5), (21, 'Geelong', 5), (22, 'Kalgoorlie', 6), (23, 'Rockingham', 6), (24, 'Bundaberg', 7), (25, 'Caloundra', 7), (26, 'Townsville', 7), (27, 'Mount Isa', 7), (28, 'Mount Barker', 8), (29, 'Victor Harbor', 8), (30, 'Hobart ', 10), (31, 'Launceston', 10), (32, 'Sitka', 11), (33, 'Juneau', 11), (34, 'Wrangell', 11), (35, 'Anchorage', 11), (36, 'Los Angeles', 12), (37, 'San Diego', 12), (38, 'New York City', 13), (39, 'Rome', 13), (40, 'North Port', 14), (41, 'Jacksonville', 14), (42, 'Bunnell', 14), (43, 'Tampa', 14), (44, 'Beaumont', 15), (45, 'Waco', 15), (46, 'Marana', 16), (47, 'Eloy', 16), (48, 'Cleveland', 17), (49, 'Cincinnati', 17), (50, 'Jackson', 18); |
use the below php file that will show a drop down box for you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php // database connection $linkfirst = mysql_connect('localhost', 'root', ''); if (!$linkfirst) { die('Could not connect: ' . mysql_error()); } mysql_select_db('test', $linkfirst) or die('Could not select database.'); //query for selecting user information $query = "SELECT * FROM tbl_city"; $results = mysql_query($query,$linkfirst) or die(mysql_error()); echo '<select name="firstdrop"> <option value="" disabled="disabled" selected="selected">choose one</option>'; while($tier=mysql_fetch_array($results)) { echo '<option value="'.$tier['city_name'].'">'.$tier['city_name'].'</option>'; } echo '</select'; ?> |