antonyfal Posted May 22, 2011 Share Posted May 22, 2011 Hi, i got help earlier with the this code-- exploding a field and getting an array, then inserting the array into a multiselect box-- That part is easy and works fine. Now the explode function gives an array of words with duplicate words in it: I tried several ways most either give a blank option/value, or the array word.. here is the code: $query = "SELECT DISTINCT property_functionsexperience FROM #__users_profiles WHERE published = '1' ORDER BY property_functionsexperience ASC"; $functionsexperiencelistgeneral=doSelectSql($query); foreach($functionsexperiencelistgeneral as $words) $property_funcexperilist=$words->property_functionsexperience; $wording = explode(', ', $property_funcexperilist); foreach($wording as $funciex) $funcexi=array_unique($funciex); $funcexpList .= "<option value=\"".$funcexi.','."\">".$funcexi."</option>"; $funcexpList .= "</optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; this code is adapted slightly from the working original that gives the double words-- this code gives a blank, but i think its on the correct track!? Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/ Share on other sites More sharing options...
antonyfal Posted May 22, 2011 Author Share Posted May 22, 2011 im guessing this is not an easy one to solve am i correct in useing the array_unique function? i know im useing it incorrectly, i have no results, but is it the correct function to use here? for the exploded words? please assist me here. Regards Antony Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/#findComment-1218849 Share on other sites More sharing options...
Zurev Posted May 22, 2011 Share Posted May 22, 2011 $query = "SELECT DISTINCT property_functionsexperience FROM #__users_profiles WHERE published = '1' ORDER BY property_functionsexperience ASC"; $functionsexperiencelistgeneral=doSelectSql($query); foreach($functionsexperiencelistgeneral as $words) $property_funcexperilist=$words->property_functionsexperience; $wording = explode(', ', $property_funcexperilist); $wording = array_unique($wording); foreach($wording as $funciex) $funcexpList .= "<option value=\"".$funcexi.','."\">".$funcexi."</option>"; $funcexpList .= "</optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; That should work, you may want to think on making easier to read variable names, and ones that better describe what you're doing, otherwise later on it's going to be hard for you to remember what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/#findComment-1218850 Share on other sites More sharing options...
antonyfal Posted May 22, 2011 Author Share Posted May 22, 2011 thanks for the help-- The long names comes from the search and replace function in my editor-- I have many dropdown lists to make, for regform, admin area, search and edits-- I know you right about later editing... Thanksa stack Zurev. Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/#findComment-1218851 Share on other sites More sharing options...
Pikachu2000 Posted May 22, 2011 Share Posted May 22, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/#findComment-1218854 Share on other sites More sharing options...
jcbones Posted May 23, 2011 Share Posted May 23, 2011 There are a couple of easy ways to make your functions/variables more readable. 1. Capitalize the first letter of each word. $PropertyFunctionsExperience; 2. Separate each word with an underscore. $property_functions_experience; Quote Link to comment https://forums.phpfreaks.com/topic/237155-help-to-remove-duplicate-words-after-a-comma-explode-function-select-lists/#findComment-1218883 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.