11t1 Posted May 9, 2007 Share Posted May 9, 2007 Hi, I was just wondering if someone could point me to a good web resource that could help me figure out how to convert a string of comma separated values (being pulled from a database) into a select menu (pulldown box) so that the values from the CSV would automatically fill in the displayed text area of the option tags as well as the value attribute so the value selected could actually be passed as a variable. I imagine it has something to do with converting the CSV list into an array using substring parsing & then dynamically building the array from the elements of the array, but I just haven't been able to put it all together yet. If anyone is familiar with anything published on the web that might help, I'd be deeply appreciative. thx - stv Quote Link to comment https://forums.phpfreaks.com/topic/50635-solved-convert-csvs-to-select-option-values/ Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 assuming what your meaning... $text='lots, and lots, and lots of words'; $array=explode(',',$text); echo '<select>'; foreach($array as $k=>$v){ echo '<option value="'.$k.'">'.trim($val).'</option>'; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/50635-solved-convert-csvs-to-select-option-values/#findComment-248892 Share on other sites More sharing options...
11t1 Posted May 9, 2007 Author Share Posted May 9, 2007 Thanks. Problem solved. Mind you, you gave me a fish when what I really wanted to do was learn how to fish, but at least I won't go hungry today. Quote Link to comment https://forums.phpfreaks.com/topic/50635-solved-convert-csvs-to-select-option-values/#findComment-248919 Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 LOL $text='lots, and lots, and lots of words'; #string with ,es $array=explode(',',$text);#turns it into an array... $array=array("lots","and lots","and lots of words"); echo '<select>'; foreach($array as $k=>$v){ #for each of the array, split it into its $k=key, $v=value echo '<option value="'.$k.'">'.trim($v).'</option>'; } echo '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/50635-solved-convert-csvs-to-select-option-values/#findComment-248923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.