java
sql
php
iphone
c
xml
python
linux
ruby-on-rails
mysql
eclipse
flash
oracle
cocoa
delphi
apache
mvc
asp
api
postgresql
I this code needs to be reworked. It's doing a lot of work in PHP that should be done in SQL. Do you have the ability to create new MySQL tables? If so, I would create 2 new tables (prefixes, suffixes) and I would pull the states query into the main query so you're not doing a separate query (extra DB hit).
As an example, here is how I'd do the prefixes table:
create table prefixes ( prefix_id integer primary key, prefix_string varchar(20) ); insert into prefixes (prefix_id, prefix_string) values (1, 'Mr.'); insert into prefixes (prefix_id, prefix_string) values (2, 'Mrs.'); ... etc ...
Then the main query would be something like:
select c.*, p.prefix_string from customer c, prefixes p where c.prefix = p.prefix_id;
Then you'd be able to use prefix_string directly instead of the if/else mess. Do the same with suffixes and states.
prefix_string
If you don't have the ability to create tables, then I'd create PHP functions which convert the integer IDs to appropriate strings.
If there's a problem you'll have to isolate it in this code to resolve it, it's a bit messy at the moment. It looks like the recordID GETVAR is being used to lookup a user account in the database. You should verify an id is getting passed in the request and that the user account is getting loaded from the database. Then step through an find out what else might not be working, you can clean up the code as you go. I've started out by cleaning up those spurious else if blocks.
Prefix Block
$aPrefixMap = array( 1 => 'Mr.', 2 => 'Mrs.', 3 => 'Ms.', 4 => 'Mr. & Mrs.', 5 => 'Dr.', 6 => 'Dr. & Mrs.', 7 => 'Mr. & Dr.', 8 => 'Drs.', 9 => 'Hon.', 10 => 'Hon. & Mrs.', 11 => 'Mr. & Hon.', 12 => 'Hons.', 13 => 'Rev.', 14 => 'Rev. & Mrs.', 15 => 'Atty.', 16 => 'Atty. & Mrs.', 17 => 'Mr. & Atty.', 18 => 'Attys.', 19 => 'Sen.', 20 => 'Sen & Mrs.', 21 => 'Mrs. & Sen.', 22 => 'Sens.', 23 => 'Rep.', 24 => 'Rep. & Mrs.', 25 => 'Mr. & Rep.', 26 => 'Reps.', 27 => 'Mayor', 28 => 'Admin' ); $iPrefix = $row_DetailRS1['prefix']; if(array_key_exists($iPrefix, $aPrefixMap)) echo $aPrefixMap[$iPrefix];
Suffix Block
$aRowDetailMap = array( 1 => 'Sr.', 2 => 'Jr.', 3 => 'I', 4 => 'II', 5 => 'III', 6 => 'IV', 7 => 'V', 8 => 'Esq.' ); $iDetailSuffix = $row_DetailRS1['suffix']; if(array_key_exists($iDetailSuffix, $aRowDetailMap)) echo $aRowDetailMap[$iDetailSuffix];