this is my current if statement <OPTION". if($section == "events") {echo "selected"; } .">Events</OPTION>
and it does not like it, isn't there someway for like a short hand if statement?
Thanks
one line if statement?
Moderator: General Moderators
- webgroundz
- Forum Commoner
- Posts: 58
- Joined: Thu Jun 21, 2007 1:20 am
- Location: Philippines
HtmlOption Class
This is where you can use a nice little class
put this code in a separate file HtmlOptionLib.php
the you can do something like
This really simplifies your code IMHO
put this code in a separate file HtmlOptionLib.php
Code: Select all
class HtmlOption
{
function toHtml($name,$val,$options, $extra="",$isEditable=true,$size=1)
{
echo HtmlOption::toStr($name,$val,$options, $extra,$isEditable,$size);
}
function toStr($name,$val,$options, $extra="",$isEditable=true,$size=1)
{
if ($isEditable)
{
$str="<select name='{$name}' id='{$name}' size='$size' $extra>\n";
foreach ($options as $key => $value)
{
$sel = ( strcmp($key,$val) == 0) ? ' selected="selected"' : '';
$str .=" <option value='$key'{$sel}>". $value ."</option>\n";
}
$str .="</select>\n";
return $str;
}
else
{
$value = $options[$val];
return "<input readonly=\"readonly\" type=\"text\" name=\"{$name}\" value=\"{$value}\" >";
}
}
}//end of classCode: Select all
require_once 'HtmlOptionLib.php';
$options = array('5'=>'Car','6'=>'Dog','9'=>'Wahtever');//always key=> value array
HtmlOption::toHtml('myvalue',9,$options);- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Why do you have false before true in the ternary statement...? And why so many closing parentheses?webgroundz wrote:here's my sample code snippet:
Code: Select all
count($this->getErrorMessages())) ? FALSE : TRUE;![]()
![]()