NickName field to First Name

I am stuck again. I have this code which is for a custom module (Groups duplicate) in conjunction with the Sub-Profiles module:

        /* this section checks logged in member to see if they are a sub-profile
or not. */

    $aParent = mysql_query("SELECT * FROM `Profiles` WHERE `ID` = '" .
$_COOKIE['memberID'] . "'");
        while ($row = mysql_fetch_array($aParent)) {
        $parent_profile = $row["parent_profile"];
        $parent_id = $row["ID"];
        }
       
    if ($parent_profile != "0") { /* If they are not a Sub-Profile creator, then get the sub-profile creators
ID number and list all sub-profiles created by that person. */
        $aProviders = $GLOBALS['MySQL']->getPairs("SELECT `ID` ,
`NickName` FROM `Profiles` WHERE `parent_profile` = '$parent_profile'",
'NickName', 'NickName');
           
    }
    else { /* If they are Sub-Profile creator, then list all sub-profiles created by the logged in user. */
        $aProviders = $GLOBALS['MySQL']->getPairs("SELECT `ID` ,
`NickName` FROM `Profiles` WHERE `ID` = '$parent_id' OR `parent_profile` =
'$parent_id'", 'NickName', 'NickName');
    }

Then I have a form using the dolphin forms coding with this field:


                'provider' => array(
                    'type' => 'select',
            'values' => $aProviders,           
                    'name' => 'provider',
                    'caption' => _t('_cf_clients_form_caption_provider_id'),
                    'required' => true,
                    'db' => array (
                        'pass' => 'Xss',
                    ),
                    'display' => true,
                ),

As it is right now, it works. It retrieves the sub-profiles and then lists them in the select field.

But - I am asking for help because I need to display the sub-profiles as First Name and Last Name, not NickName (snapshot3). As you will notice in the last visible select field there is ProfessorSr74 - I want it to say Calvin Fowler.

I do have my advanced settings set to use First Name Last Name

Any help would be appreciated. Thanks in advance.

snapshot3.png · 222K · 156 views
caredesign.net
Quote · 8 Aug 2014

Look at your queries again. Your pulling nicknames. So that is what your going to get. Your display settings in admin being set to first, last is not going to do you much good because your reading directly from the database.


https://www.deanbassett.com
Quote · 9 Aug 2014

 I totally understand. I guess my question is - what should my query be in order to get the desired result?

Look at your queries again. Your pulling nicknames. So that is what your going to get. Your display settings in admin being set to first, last is not going to do you much good because your reading directly from the database.


 

caredesign.net
Quote · 9 Aug 2014

You will need to pull the first name and last name and do a concatenation FirstName . LastName but I am unsure how you would populate the drop down box and whether or not it would screw up the form.

Geeks, making the world a better place
Quote · 9 Aug 2014

you would not be able to use the getPairs database function. That was written for 2 values only. You appear to be building and array in which both the key and the value is the same. If you still need nickname as the key then you need to pull 3 values from the database.

Something like this.

$aRows = $GLOBALS['MySQL']->getAll("SELECT `NickName`, `FirstName`, `LastName` FROM `Profiles` WHERE `parent_profile` = '$parent_profile'");

Then loop though that and build the $aProviders array.

$aProviders = array();
foreach($aRows as $id => $value) {
   $aProviders($value['NickName']) = $value['FirstName'] . ' ' . $value['LastName'];
}

https://www.deanbassett.com
Quote · 9 Aug 2014

Thanks Deano - you are a miracle worker/genius.

caredesign.net
Quote · 9 Aug 2014

For some reason I am getting this error:

Fatal error: Can't use function return value in write context in /home/yourthe/public_html/CareDesign-1.0.2/modules/mts/clients/classes/CfClientsFormAdd.php on line 181

Line 181 is:

$aProviders($value['NickName']) = $value['FirstName'] . ' ' . $value['LastName'];

caredesign.net
Quote · 9 Aug 2014

Opps.

This line...

$aProviders($value['NickName']) = $value['FirstName'] . ' ' . $value['LastName'];

Should be this.

$aProviders[$value['NickName']] = $value['FirstName'] . ' ' . $value['LastName'];


I used the wrong brackets.

Anyhow. I am not even sure this code will work. I have not tested it. I can't test it. Obviously because i don't have one of the profile fields your referencing. So this is all guesswork which i hate doing.

https://www.deanbassett.com
Quote · 9 Aug 2014

Your Guesswork is better than my actual workings - I swear you are the best Deano. The bracket change works perfectly

snapshot8.png · 232K · 166 views
caredesign.net
Quote · 9 Aug 2014

> $aParent = mysql_query("SELECT * FROM `Profiles` WHERE `ID` = '" . $_COOKIE['memberID'] . "'");

Please be careful with that - SQL injection (a hack) vulnerability (because it is possible to substitute cookies)

Quote · 9 Aug 2014

thanks Andrew - I have to go through all of my coding and make changes. I did not think about that fact.

caredesign.net
Quote · 9 Aug 2014
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.