I need to retrieve data from a database and I have no way to change its structure. There are 3 distinct fields for address:
Personal: client_address_1, client_address_2, client_address_3, client_address_4
Postal: client_postaladdress_1, client_postaladdress_2, client_postaladdress_3, client_postaladdress_4
Company: client_company_address_1, client_company_address_2, client_company_address_3, client_company_address_4
and one field (client_prefered_address) which contains in which address the client wants to receive his correspondence.
From them I need to retrieve the address of choice, so, if the client is marked as postal, it should return the columns: client_postaladdress_1, client_postaladdress_2, client_postaladdress_3, client_postaladdress_4 but not the others.
Is there any way to do it? I have been Googling for two days.
Thanks
SQL:
CREATE TABLE IF NOT EXISTS `client` (
`client_id` int(11) NOT NULL AUTO_INCREMENT,
`client_address_1` varchar(255) COLLATE utf8_bin NOT NULL,
`client_address_2` varchar(255) COLLATE utf8_bin NOT NULL,
`client_address_3` varchar(255) COLLATE utf8_bin NOT NULL,
`client_address_4` varchar(255) COLLATE utf8_bin NOT NULL,
`client_postaladdress_1` varchar(255) COLLATE utf8_bin NOT NULL,
`client_postaladdress_2` varchar(255) COLLATE utf8_bin NOT NULL,
`client_postaladdress_3` varchar(255) COLLATE utf8_bin NOT NULL,
`client_postaladdress_4` varchar(255) COLLATE utf8_bin NOT NULL,
`client_company_address_1` varchar(255) COLLATE utf8_bin NOT NULL,
`client_company_address_2` varchar(255) COLLATE utf8_bin NOT NULL,
`client_company_address_3` varchar(255) COLLATE utf8_bin NOT NULL,
`client_company_address_4` varchar(255) COLLATE utf8_bin NOT NULL,
`client_prefered_address` char(10) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`client_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=4;
--
-- Dumping data for table `client`
--
INSERT INTO `client` (`client_id`, `client_address_1`, `client_address_2`, `client_address_3`, `client_address_4`, `client_postaladdress_1`, `client_postaladdress_2`, `client_postaladdress_3`, `client_postaladdress_4`, `client_company_address_1`, `client_company_address_2`, `client_company_address_3`, `client_company_address_4`, `client_prefered_address`) VALUES
(1, 'Yellow house', 'Yellow street, 25', '09090 Yellow city', 'Yellow Country', 'Blue postbox', 'Blue avenue, 90', '09039 Blue city', 'Blue Country', 'Green house', 'Green street, 100', '02930 Green city', 'Green Country', 'Postal'),
(2, 'Apple house', 'Apple street, 200', 'Apple State 2039', 'Apple Land', 'Melon House', 'Melon Boulevard ', 'Melon State ', 'Melon Land', '', '', '', '', 'Personal'),
(3, '', '', '', '', '', '', '', '', 'Chocolate Factory', 'Charlie street 293', 'Chocolate CH', 'Chocolate Kingdom ', 'Company');