0

We have a 3rd party component and in the database there is a column clled options which contains the users gender - COM_COMMUNITY_MALE and COM_COMMUNITY_FEMALE. When we read this information in using this code

$SQL = "SELECT * FROM #__community_fields a WHERE a.fieldcode like 'FIELD_GENDER%'";


$db->setQuery($SQL);
$rows = $db->loadObjectList();

$html = "<option value =' '>Select Gender</option>";    

foreach ($rows as $data)
{   
    $xxx = explode("\n", $data->options);


for ($i = 0; $i < count($xxx); ++$i) {

    if ($xxx[$i] == "COM_COMMUNITY_MALE")
    {
        print $xxx[$i];
    }

}

        $html = $html . "<option value ='".$arr."'>".$gender."</option>";       

}       

echo $html;

The check for $xxx[$i] == "COM_COMMUNITY_MALE" does not print the value. If we just print $xxx[$i] then we do see the correct values but when we do the check if fails the test

We need to distinguish the gender so we can ste the values in the dropdown

Any help would really be appreciated

Thanks Rich

1 Answer 1

3

Get rid of the quotes around your constant. That makes it a string with a value of "COM_COMMUNITY_MALE" and not your constant:

if ($xxx[$i] == COM_COMMUNITY_MALE)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks John, That sorted it Rich

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.