antonyfal Posted May 22, 2011 Share Posted May 22, 2011 Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/ Share on other sites More sharing options...
wildteen88 Posted May 22, 2011 Share Posted May 22, 2011 If all $allwordsgenral contains a comma delimited list of words then change <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; to <optgroup label=\"Others added\">\n"; $words = explode(',', $allwordsgeneral); foreach($words as $word) $funcexpList .= "<option value=\"".$word."\">".$word."</option>\n"; $funcexpList .= "</optgroup>"; NOTE: When posting code please wrap it within or ) tags. Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/#findComment-1218682 Share on other sites More sharing options...
antonyfal Posted May 22, 2011 Author Share Posted May 22, 2011 Hi thanks for the fast reply. I tried your code in several ways but i keep getting only one word in the <optgroup> others added the word is "array" Am i missing something? thanks Tony Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/#findComment-1218689 Share on other sites More sharing options...
wildteen88 Posted May 22, 2011 Share Posted May 22, 2011 Where is $allwordsgeneral defined? Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/#findComment-1218690 Share on other sites More sharing options...
antonyfal Posted May 22, 2011 Author Share Posted May 22, 2011 ahh sory here is where it is defined: $query = "SELECT DISTINCT profile_functionsexperience FROM #__functions_experience WHERE published = '1' ORDER BY profile_functionsexperience ASC"; $allwordsgeneral=doSelectSql($query); foreach ($allwordsgeneral as $allwordsalsgeneral) { $profile_allwordsgeneral=$allwordsalsgeneral->profile_functionsexperience; } Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/#findComment-1218697 Share on other sites More sharing options...
antonyfal Posted May 22, 2011 Author Share Posted May 22, 2011 SORRY YOU WERE CORRECT! i only added the commas to the options array after i already saved the first test to the database. So i was explodeing the data at an invisible "comma" its working perfectly now-- thanks for the assistance.. I did however remove the "$funcexpList .= "" from the code you gave me-- it worked either way. regards Antony Quote Link to comment https://forums.phpfreaks.com/topic/237113-explode-array-list-need-to-break-values-from-msql-text-box-for-select-list/#findComment-1218712 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.