Jump to content

Help to remove duplicate words after a comma explode function- select lists


antonyfal

Recommended Posts

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!?

im guessing this is not an easy one to solve :confused:

 

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

$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.

;D 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.

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.