PDA

View Full Version : rewrite this code


Princeton
01-23-2004, 03:21 PM
is there an easier / more productive way to rewrite this code:
$radio6CHECKED = ($newpost['radio2']=='1')? HTML_CHECKED: "";
$radio7CHECKED = ($newpost['radio2']=='2')? HTML_CHECKED: "";
$radio8CHECKED = ($newpost['radio2']=='3')? HTML_CHECKED: "";
$radio9CHECKED = ($newpost['radio2']=='4')? HTML_CHECKED: "";
$radio10CHECKED = ($newpost['radio2']=='5')? HTML_CHECKED: "";

thank you

NTLDR
01-23-2004, 03:30 PM
switch($newpost['radio2']) {

case 1:
$radio6CHECKED = HTML_CHECKED;
break;
case 2:
$radio7CHECKED = HTML_CHECKED;
break;
case 3:
$radio8CHECKED = HTML_CHECKED;
break;
case 4:
$radio9CHECKED = HTML_CHECKED;
break;
case 5:
$radio10CHECKED = HTML_CHECKED;
break;
}


Maynot be more productive, but its another way none the less.

Princeton
01-23-2004, 03:44 PM
LOL
thank you NTLDR ... I use switch/case statement but, I'm looking for something shorter/simpler.

Xenon
01-23-2004, 10:47 PM
hmm as you use a follow up counter method, this should work also:


eval('$radio' . (5 + $newpost['radio2']) . 'CHECKED = HTML_CHECKED;');

Princeton
01-24-2004, 01:01 AM
I gotta check that out ... thank you.:up:

Princeton
01-24-2004, 04:13 PM
Xenon,
I'm not having any luck with the code.:( It's not recognizing which radio button was clicked.

Xenon
01-25-2004, 12:30 AM
hmm, wierd, i think it should work...

Princeton
01-25-2004, 02:12 AM
I'll rephrase that ... on preview it doesn't recognize which radio was clicked

Xenon
01-25-2004, 07:49 PM
ahh :)

that would expalin it :)
i've also had problems with the checked boxes and preview..