I’m stuck outputting data from a table like this. This is a table for profiles.
CREATE TABLE `prod_profiles` (
`p_add` VARCHAR(300) NULL DEFAULT NULL,
`p_add_s` TINYINT(1) NULL DEFAULT '0',
`p_phone` VARCHAR(300) NULL DEFAULT NULL,
`p_phone_s` TINYINT(1) NULL DEFAULT '0',
//and many more
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM;
Over here, p_add is the address, p_add_s (anything with the _s) is the part which decides if a user would like to display this data or not (0 is display, 1 is hide).
I need to display data like: (this is the admin section)
Address data goes here if (p_add_s = 0) {echo 'Hide';} else {echo 'Unhide';}
Phone data goes here if (p_phone_s = 0) {echo 'Hide';} else {echo 'Unhide';}
My problem is how do i tell php to print the first column and then check the _s columns value without using all the columns names in php like below. I’m lost here.
The way I’m doing it now is:
while($form_data = mysql_fetch_array($exe_prof_form))
{
echo $form_data['sc_p_add']; if ($form_data['sc_p_add_s'] ==0){echo "Hide";}else{echo "Show";
//Remaining fields go here
// Any way I can get rid of these fields and do what I'm trying?
}
Well, I came up with this: (Warning: Ugly Code ahead)
Does the job… Tell me what you think.