Jump to content

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


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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.