Page 1 of 1
Need a Link or Basic Script to Learn Select Functionality
Posted: Tue Sep 02, 2014 7:27 pm
by diseman
Hi All,
The Problem: I'm trying to learn how to take records from one table -> name (Tom, Jim, Chris, Mike) and put them into a SELECT (drop down menu) box, then select a name and save it to a DIFFERENT table, and then have that selection show in the SELECT box as SELECTED.
I have found a hundred websites showing how to bind a SELECT box to a table and put them into a SELECT box via $key => $val and even how to save it to ANOTHER textbox on the page, which is a lot easier, but never a step further as described in the first paragraph. Seems unbelievable to me since it's so common. Maybe I'm just not using the proper search terms/keywords.
Does anyone have a link to a site that shows how to do this... or maybe have something very basic that would show me the process?
Thanks in advance for any help!
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Tue Sep 02, 2014 8:51 pm
by Celauran
Is this a foreign key reference type of situation?
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 8:48 am
by diseman
Hi Celauran,
No, it's not. Remember, I'm just learning PHP, so everything is at the most basic level. Names I'm retrieving from one table to put in another are all based on account's username, which is an email address.
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 8:56 am
by Celauran
Just trying to get a handle on what you're aiming to accomplish before I suggest solutions. I was thinking the behaviour was similar to, say, you're creating a new city entry and you get all countries from your countries table so you can save the country_id in your cities table. If I'm off base with that assumption, can you please try to clarify what you're trying to do?
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 9:10 am
by diseman
Yes, off base a little because the names I'm pulling from the notifications table are entered by the user on the notifications page. So, as an example, let's say you wanted to notify 3 people of your birthday. On the notification page, you would enter three names in separate input textboxes with [keys]. So, you put in John, Chris, and Tom. Done.
Now, on the other page, I have -- say .... five select boxes. For arguments sake, let's just say I click on all of them one at a time. On each of them, I would only see three names (John, Chris, and Tom). Now, in the first SELECT box I click on John. In the second select box I click on Chris, and on the third I click on Tom. Then save the form. I would like to see John, Chris, and Tom in the first three boxes after refreshing and I would like to see SELECT A NAME on the last two Select boxes that we never did anything with.
So, there are NO names in the original name row (similar to your city reference) to begin with. They are populated by the user.
Here is the table for the names to be entered by the user and then to be drawn upon on the other page.
Code: Select all
id int(32) unsigned auto_increment NOT NULL,
userid int(32) unsigned NOT NULL,
username varchar(255) NOT NULL,
name varchar(255),
selected_name varchar(64),
relationship varchar(255),
address varchar(255),
email varchar(255),
phone varchar(12),
PRIMARY KEY (id)
Here's the other table that would store the selections made from the table above.
Code: Select all
id int(32) auto_increment NOT NULL,
userid int(32) unsigned NOT NULL,
username varchar(255) NOT NULL,
name varchar(64),
instruction text,
PRIMARY KEY (id)
Hope I'm making sense...

Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 9:16 am
by Celauran
So you can notify up to five people. You create five select lists, each containing all the names available, and the first list will show the first name you specified as being selected, the second list shows the second name as selected, etc and nothing is selected when n > the number of names already specified?
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 10:26 am
by diseman
Technically, user could add as many names as he/she wanted to be notified, but my example was only three names entered.
Number of select boxes is actually pre-determined by me with a javascript I found that I like. By default, I think I have three Select boxes showing. By clicking an add/delete button, I can add or delete Select boxes to the page.
Nothing is selected when I haven't selected anything. Meaning, if I had three names in the original table and then only selected 1 name on the page, the other two Select boxes would only show "Select a Name" in the box.
One last thing you made me think of. I believe (will check when I get back), the number of Select boxes is also determined by how many saved entries I've made. So, even though my default may only be three boxes - if I had 7 names in the table and then added 4 Select boxes to the default number, I would always see 7 boxes if I had selected and saved 7 names.
Thank you again
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 10:39 am
by Celauran
Any reason you aren't using checkboxes or a multiselect, then?
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Wed Sep 03, 2014 2:34 pm
by diseman
If you look at the 2nd table, you'll see that I have another row called INSTRUCTION and that's a textarea assigned to EACH name selected from the Select menu. It is meant only for one person per row.
P.S. I've added an attachment for you to see what it looks like on my screen.
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Thu Sep 04, 2014 11:58 am
by diseman
still there?
Re: Need a Link or Basic Script to Learn Select Functionalit
Posted: Thu Sep 04, 2014 12:04 pm
by Celauran
Your relationship is defined on names? (i.e. name entry in second table matches user with name in users table)
If so, you'd want to select all names from the names table. Just select all of them. Separately, you'd select the relevant records from the second table. You iterate over the results to create your form rows, iterate over the names array to create your selects and, as you're iterating over it, compare the current name from names array with the value of name from your current form row. Does that make sense?