PHP Templates and HTML Select

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce

    PHP Templates and HTML Select

    For those of you using templates to keep your PHP and HTML code
    separate.....

    How do you handle a HTML Select statement when the initial option
    selected needs to come from a database field?

    --Bruce

  • Andy Hassall

    #2
    Re: PHP Templates and HTML Select

    On Thu, 11 Mar 2004 13:21:54 GMT, Bruce <brucev2@hotmai l.com> wrote:
    [color=blue]
    >For those of you using templates to keep your PHP and HTML code
    >separate.... .
    >
    >How do you handle a HTML Select statement when the initial option
    >selected needs to come from a database field?[/color]

    Well, depends on the templating system. I use Smarty, so I use:

    <http://smarty.php.net/manual/en/language.functi on.html.options .php>

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    <http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>

    Comment

    • rush

      #3
      Re: PHP Templates and HTML Select

      "Bruce" <brucev2@hotmai l.com> wrote in message
      news:bhp0509nks n8hbl8onh9qbr7k 9pql60k2t@4ax.c om...[color=blue]
      > For those of you using templates to keep your PHP and HTML code
      > separate.....
      >
      > How do you handle a HTML Select statement when the initial option
      > selected needs to come from a database field?[/color]

      With TemplateTamer, I usually have template along these lines:

      <select name="optionCho oser">
      <!--NAME:OPTION-->
      <option value="{OPTIONV ALUE}" {OPTIONSELECTED }>{OPTIONNAME} </option>
      <!--END:OPTION-->
      </select>

      And then in logic file:

      foreach ($options as $optValue => $optName) {
      if ($optValue == $selectedValue)
      $selected = 'SELECTED';
      else
      $selected= '';
      $opt[] = array(
      'OPTIONVALUE' => $optValue ,
      'OPTIONNAME' => $optName,
      'OPTIONSELECTED '=> $selected
      );
      }


      You can see more on that example at:



      rush
      --



      Comment

      Working...