Hello All,
Wondering if someone can help me with a tiny problem i’m having that’s driving me potty (and I know when I find the answer I will be annoyed with myself!!!).
Take this code:
$html .= '<option value="'.$key.'">'.$value.'</option>' . "\
";
Basically I want to add an if statement in there:
if ($input_value == ''.$key.'') echo ' selected'
However, everytime I add the thing I get a pesky parse error?
Thanks
JREAM
October 26, 2010, 11:15am
2
Are you $_POST 'ing the $input_value?
I would do echo $input_value and echo $key to see what they say,
$input_val = $_POST['the_field_here']; // <-- are you doing that?
if ($input_val == $key) echo ' selected';
echo $input_val;
echo ' <-- input | key -->';
echo $key;
if you need to fix whitespace use trim()
harikt
October 26, 2010, 11:22am
3
Use something like this . Hope it helps
if ($input_value == ''.$key.'') {
$html .= '<option value="'.$key.'">'.$value.'</option>' . "\
";
} else {
$html .= '<option value="'.$key.'" "selected" >'.$value.'</option>' . "\
";
}