Forum Moderators: coopster

Message Too Old, No Replies

Dropdown menus

         

mtnbiker717

12:05 am on May 12, 2009 (gmt 0)

10+ Year Member



First off, I want to say thanks for any help, I am sure I am asking a loaded question, any help will be accepted since I have taught myself all I know from books and the web. This is what I want to do, I need some sort of script that will allow me to have 2 drop down menus - one menu will be for the 'State' and the other will be for the 'Day' of the week.

About my mysql database that I am pulling from - I have various 'Venues' in 3 'States' and certain 'Day' that there is an event at the venue.

-- phpMyAdmin SQL Dump
-- version 2.6.2-pl1
-- [phpmyadmin.net...]
--
-- Host: localhost
-- Generation Time: May 11, 2009 at 04:06 PM
-- Server version: 4.1.22
-- PHP Version: 4.4.9
--
-- Database: `**********`
--

-- --------------------------------------------------------

--
-- Table structure for table `Location`
--

CREATE TABLE `Location` (
`id` int(11) NOT NULL auto_increment,
`Venue` varchar(100) NOT NULL default '',
`Day` varchar(10) NOT NULL default '',
`Start` varchar(10) NOT NULL default '',
`Address` varchar(100) NOT NULL default '',
`City` varchar(20) NOT NULL default '',
`State` varchar(20) NOT NULL default '',
`Zip` varchar(5) NOT NULL default '',
`Phone` varchar(14) NOT NULL default '',
`New` char(3) NOT NULL default 'No',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=34 DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;

<snipped data dump -- file layout is good enough>

When I created a drop down menu and pulled the States into it, it populates a State for each row above. I fixed that by changing ORDER by to GROUP by.

This is where I am stuck, how can I use the 3 results from the 1st drop down to create and populate a second drop down menu with the days of the week. I found a couple scripts online and each hung up when I did a GROUP by - in the day drop down it would only show one value such a Wednesday for only one row, couldn't figure it out.

I have figured out how to staticaly do it, but I would prefer to do it dynamicaly for future changes that may need to be made.

From there, I would like to "POST" the results through the URL. I have figured out how to do that with a very simple form, but I can't figure out the multiple drop down menus. Once I get the 2 drop downs working and posted in the URL I am set from there. Joys of saying you can do something for someone when you’re not sure, right? Lesson learned!

[edited by: coopster at 1:29 pm (utc) on May 12, 2009]
[edit reason] Removed unnecessary data dump [/edit]

coopster

1:20 pm on May 21, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, mtnbiker717.

Large code posts tend to steer folks away from discussion and may have been the case here.

When I created a drop down menu and pulled the States into it, it populates a State for each row above. I fixed that by changing ORDER by to GROUP by.

GROUP BY will create distinct rows for you by grouping all the rows with like columns specified into a single summary row for each. You can then apply the ORDER BY to sort the result set. Something like:

SELECT State FROM Location GROUP BY State ORDER BY State;

To populate the "Day" drop down you could run a similar query replacing "State" with "Day".

To carry the value from the first selection (State) on through to the next display or stage of your process you could write the State selection to a hidden form field, set a cookie, use a session, carry it in the QUERY STRING, etc. The hidden form field may be easiest.

mtnbiker717

5:04 am on May 22, 2009 (gmt 0)

10+ Year Member



Coopster, thank you for the reply, that has worked for me and thank you for the tip about posting code. I just want to say to everyone out there helping me and others, thank you. I have found that this community is very helpful, thanks!