[SOLVED] Create dropdown menu from comma separated list of numbers

03-02-07, 03:14 PM
|
|
Newbie Coder
|
|
Join Date: Nov 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
[SOLVED] Create dropdown menu from comma separated list of numbers
Hello people,
I'm not too good with the PHP and need some code which will automatically create dropdown menu from comma separated list of numbers.
For example if I have this:
1,2,3,4,5,6,7,8,9
code needs to build menu with listed numbers as options. It will look like this:
1
2
3
4
5
6
7
8
9
When I change numbers in comma separated list then menu needs to change automatically to new options.
So if I change it to:
25,30,35,40,45,50
menu options changes to:
25
30
35
40
45
50
I need to put it later to HTML document.
Thanks in advance.
|

03-02-07, 03:38 PM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

03-03-07, 05:11 AM
|
|
Newbie Coder
|
|
Join Date: Nov 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you very much. Works fine!
|

01-21-09, 05:54 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Stumbled across this when looking for something similar.
If I wanted to replace the list of numbers with a comma separated item from a database, how would I go about that?
I tried the following, and it doesn't work:
In this, my list of separated values is "reg_values_userfield1", in the database under igive_config
Any help is appreciated.
|

01-21-09, 11:53 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
I am assuming there is only one record in the igive_config table
and the column reg_values_userfield1 contains a comma delimited string of numbers.
ie: 1,2,3,4,5,6,7,8,9
Also, the option element's value will default to the option's text if a value isn't specified.
So you don't need to specify the value as $option and the text as $option.
The reason your code didn't work is because you didn't supply a resource identifier ($result) for the query.
And you are fetching the comma delimited string from reg_values_userfield1 and then you try to get the value of $row['option_list'] which doesn't exist.
This code should do what you want.
Instead of using $row = mysql_fetch_assoc($result);
you could also use $row = mysql_fetch_row($result);
and this code would work.
__________________
Jerry Broughton
Last edited by job0107; 01-22-09 at 12:08 AM.
|

01-22-09, 07:11 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Jerry,
That didn't seem to work, though. Either examples of code you provided just resulted in an empty option area.
I'll try playing around with it to see if I can get it to work, thanks for pointing me in the right direction.
|

01-22-09, 08:44 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Quote:
Originally Posted by mike_jandreau
Thanks Jerry,
That didn't seem to work, though. Either examples of code you provided just resulted in an empty option area.
I'll try playing around with it to see if I can get it to work, thanks for pointing me in the right direction.
|
When I wrote the code, I created a table in my database called igive_config
and in that table I created one column called reg_values_userfield1.
And then I created one record in that table with this data in it "1,2,3,4,5,6,7,8,9".
The data is in there exactly as it is written without the quotes.
You do the same and it will work.
To change the values in the dropdown box, you just change the comma delimited string
in that one record.
ie: "10,11,12,13,14,15,16,17,18"
Do you understand?
__________________
Jerry Broughton
|

01-22-09, 08:46 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I tried, I failed.
I apparently had the query wrong before, but I fixed that. If I run the query in the database, I get back the data from that field that I want (the comma separated data), but not for this dropdown code.
Here's what I tried:
And all I get back is:
Seems like the $option bit isn't doing what it's supposed to. Any further help is appreciated.
|

01-22-09, 08:59 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Quote:
Originally Posted by mike_jandreau
I tried, I failed.
I apparently had the query wrong before, but I fixed that. If I run the query in the database, I get back the data from that field that I want (the comma separated data), but not for this dropdown code.
Here's what I tried:
And all I get back is:
Seems like the $option bit isn't doing what it's supposed to. Any further help is appreciated.
|
Take a look at this line of code:
This query says, select the config_value column from the igive_config table where the config_name column equals the value "reg_values_userfield1".
Obviously there is no value "reg_values_userfield1" in the config_name column.
Try again.
__________________
Jerry Broughton
|

01-22-09, 09:11 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2006
Location: Boston
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by job0107
Obviously there is no value "reg_values_userfield1" in the config_name column.
Try again.
|
I thought that as, well. But if I run that same exact query in phpMyAdmin, I get the exact data I'm looking for. I'm confused why the php query doesn't pull that bit from the database.
Gives me the attached image as a result, which is the data I want. Any suggestions?
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|