Translate

Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Android Wireless Application Development
Image of Beginning Google Maps API 3
Image of Advanced Programming in the UNIX Environment, Second Edition (Addison-Wesley Professional Computing Series)

Adding Discrete Height Selection to Boonex Dolphin

Boonex’s Dolphin is a popular PHP/MySQL-based community software package which has been around for a number of years. It’s roots go back nearly 10 years to aeWebWorks and AEdating. As part of each user’s profile, it includes the ability to store a user’s height. Unfortunately the granularity of the select box options for a user’s height is poor. Here is the relevant part of the MySQL load script which sets up the user height selection values:

INSERT INTO `sys_pre_values` VALUES('Height', '1', 1, '__4''7" (140cm) or below', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '2', 2, '__4''8" - 4''11" (141-150cm)', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '3', 3, '__5''0" - 5''3" (151-160cm)', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '4', 4, '__5''4" - 5''7" (161-170cm)', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '5', 5, '__5''8" - 5''11" (171-180cm)', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '6', 6, '__6''0" - 6''3" (181-190cm)', '', '', '', '', '');
INSERT INTO `sys_pre_values` VALUES('Height', '7', 7, '__6''4" (191cm) or above', '', '', '', '', '');


As you can see the user can only pick one of a small number of options. This granularity is too course when Dolphin is used for developing an application such as a dating site. Here users expect to be able to enter their exact height not just course height bands.This post shows you how to fix this problem.

The height selection values are stored in the sys_pre_values table and hence need to be changed. Use the following MySQL script to delete the old values and insert new values in the range 140 cm to 200 cm with a granularity of 1 cm.

DELETE FROM sys_pre_values WHERE `key` = "Height";
INSERT INTO sys_pre_values (`Key`, `Value`, `Order`, `LKey`)
VALUES
( "Height",  "0",  0,  '              ' ),
( 'Height',  '1',  1,  "140 cm (4\\\'"' 7")' ),
( "Height",  "2",  2,  "141 cm (4\\\'"' 8")' ),
( "Height",  "3",  3,  "142 cm (4\\\'"' 8")' ),
( "Height",  "4",  4,  "143 cm (4\\\'"' 8")' ),
( "Height",  "5",  5,  "144 cm (4\\\'"' 9")' ),
( "Height",  "6",  6,  "145 cm (4\\\'"' 9")' ),
( "Height",  "7",  7,  "146 cm (4\\\'"' 9")' ),
( "Height",  "8",  8,  "147 cm (4\\\'"' 10")' ),
( "Height",  "9",  9,  "148 cm (4\\\'"' 10")' ),
( "Height", "10", 10,  "149 cm (4\\\'"' 11")' ),
( "Height", "11", 11,  "150 cm (4\\\'"' 11")' ),
( "Height", "12", 12,  "151 cm (4\\\'"' 11")' ),
( "Height", "13", 13,  "152 cm (5\\\'"' 0")' ),
( "Height", "14", 14,  "153 cm (5\\\'"' 0")' ),
( "Height", "15", 15,  "154 cm (5\\\'"' 1")' ),
( "Height", "16", 16,  "155 cm (5\\\'"' 1")' ),
( "Height", "17", 17,  "156 cm (5\\\'"' 1")' ),
( "Height", "18", 18,  "157 cm (5\\\'"' 2")' ),
( "Height", "19", 19,  "158 cm (5\\\'"' 2")' ),
( "Height", "21", 21,  "159 cm (5\\\'"' 3")' ),
( "Height", "22", 22,  "160 cm (5\\\'"' 3")' ),
( "Height", "23", 23,  "161 cm (5\\\'"' 3")' ),
( "Height", "24", 24,  "162 cm (5\\\'"' 4")' ),
( "Height", "25", 25,  "163 cm (5\\\'"' 4")' ),
( "Height", "26", 26,  "164 cm (5\\\'"' 5")' ),
( "Height", "27", 27,  "165 cm (5\\\'"' 5")' ),
( "Height", "28", 28,  "166 cm (5\\\'"' 5")' ),
( "Height", "29", 29,  "167 cm (5\\\'"' 6")' ),
( "Height", "30", 30,  "168 cm (5\\\'"' 6")' ),
( "Height", "31", 31,  "169 cm (5\\\'"' 7")' ),
( "Height", "32", 32,  "170 cm (5\\\'"' 7")' ),
( "Height", "33", 33,  "171 cm (5\\\'"' 7")' ),
( "Height", "34", 34,  "172 cm (5\\\'"' 8")' ),
( "Height", "35", 35,  "173 cm (5\\\'"' 8")' ),
( "Height", "36", 36,  "174 cm (5\\\'"' 9")' ),
( "Height", "37", 37,  "175 cm (5\\\'"' 9")' ),
( "Height", "38", 38,  "176 cm (5\\\'"' 9")' ),
( "Height", "39", 39,  "177 cm (5\\\'"' 10")' ),
( "Height", "40", 40,  "178 cm (5\\\'"' 10")' ),
( "Height", "41", 41,  "179 cm (5\\\'"' 10")' ),
( "Height", "42", 42,  "180 cm (5\\\'"' 11")' ),
( "Height", "43", 43,  "181 cm (5\\\'"' 11")' ),
( "Height", "44", 44,  "182 cm (6\\\'"' 0")' ),
( "Height", "45", 45,  "183 cm (6\\\'"' 0")' ),
( "Height", "46", 46,  "184 cm (6\\\'"' 0")' ),
( "Height", "47", 47,  "185 cm (6\\\'"' 1")' ),
( "Height", "48", 48,  "186 cm (6\\\'"' 1")' ),
( "Height", "49", 49,  "187 cm (6\\\'"' 2")' ),
( "Height", "50", 50,  "188 cm (6\\\'"' 2")' ),
( "Height", "51", 51,  "189 cm (6\\\'"' 2")' ),
( "Height", "52", 52,  "190 cm (6\\\'"' 3")' ),
( "Height", "53", 53,  "191 cm (6\\\'"' 3")' ),
( "Height", "54", 54,  "192 cm (6\\\'"' 4")' ),
( "Height", "55", 55,  "193 cm (6\\\'"' 4")' ),
( "Height", "56", 56,  "194 cm (6\\\'"' 4")' ),
( "Height", "57", 57,  "195 cm (6\\\'"' 5")' ),
( "Height", "58", 58,  "196 cm (6\\\'"' 5")' ),
( "Height", "59", 59,  "197 cm (6\\\'"' 6")' ),
( "Height", "60", 60,  "198 cm (6\\\'"' 6")' ),
( "Height", "61", 61,  "199 cm (6\\\'"' 6")' ),
( "Height", "62", 62,  "200 cm (6\\\'"' 7")' );

You also need to modify the compilePreValues function in ../administration/preValues.php as follows:

       while( $aRow = mysql_fetch_assoc( $rRows ) ) {
            $sValue_db = addslashes( $aRow['Value'] );
            fwrite( $rProf, "    '{$sValue_db}' => array( " );

            foreach( $aRow as $sValKey => $sValue ) {
                if( $sValKey == 'Key' or $sValKey == 'Value' or $sValKey == 'Order' )
                    continue;                   // skip key, value and order. they already used
                if (!strlen( $sValue ))
                    continue;
                // new if statement to handle special Height case
                if ($sKey_db == 'Height') {
                    fwrite( $rProf, "'$sValKey' => '" . $sValue . "', " );
                } else {
                    fwrite( $rProf, "'$sValKey' => '" . addslashes( $sValue ) . "', " );
                }
            }

            fwrite( $rProf, "),\n" );
        }


This modification fixes the problem of a slash appearing before each of the double quotes used to denote inches.

After this go into the administration panel, select Settings/Predefined Values/Height/Save and the new values are written out to the predefined values cache file. Here is an example of part of what is written into /inc/prof.inc.php for height values:

  'Height' => array(
    '0' => array( ),
    '1' => array( 'LKey' => '140 cm (4\' 7")', ),
    '2' => array( 'LKey' => '141 cm (4\' 8")', ),
    '3' => array( 'LKey' => '142 cm (4\' 8")', ),
    '4' => array( 'LKey' => '143 cm (4\' 8")', ),
    '5' => array( 'LKey' => '144 cm (4\' 9")', ),
    '6' => array( 'LKey' => '145 cm (4\' 9")', ),
    '7' => array( 'LKey' => '146 cm (4\' 9")', ),
    '8' => array( 'LKey' => '147 cm (4\' 10")', ),
    '9' => array( 'LKey' => '148 cm (4\' 10")', ),
    ......
    '59' => array( 'LKey' => '197 cm (6\' 6")', ),
    '60' => array( 'LKey' => '198 cm (6\' 6")', ),
    '61' => array( 'LKey' => '199 cm (6\' 6")', ),
    '62' => array( 'LKey' => '200 cm (6\' 7")', ),
  ),


Note that a value of 0 (zero) denotes that the user had not selected any height. I like to allow users to leave fields blank if they so choose.

Well, with the above information, you should now be able to go ahead and enhance the user profile height field in your Dolphin application.
 

Comments are closed.