将选择框放在php html中

时间:2017-06-16 06:04:16

标签: php html wordpress

我想把select子句放在php html中。

这里是我的代码:

<?php 
for($index=1; $index<=$content->option->dynamic_field_index; $index++){
 echo "<td><select name='kboard_option_product' 
 id='kboard_option_product{$index}' data-placeholder='selectProduct'>";
 echo "<optgroup value='0' label='products'>";
 echo "<option value='windows'>windows</option>";
 echo "<option value='linux'>linux</option>";                
 echo "<option value='unix'>unix</option>";
 echo "</optgroup></select></td>";
 }?>

我该如何解决? 我想在

中这样做

如果查看下面的选项,您将保存这样的数据,但如果使用echo,则必须匹配php语法和html语法。

 <option value="window"<?php if($content->option->product == 'window'):?> selected<?php endif?>>window</option>

我想要做的是在php子句中使用for语句并使用带有echo的标记将其显示为html

1 个答案:

答案 0 :(得分:0)

只需使用以下内容,

function php_selectbox(){
   ob_start();
   ?>
      //Place your html here and echo the function outside.
   <?php
   return ob_get_clean();

}