2016-08-27 3 views
3

私のプロジェクトは、テキストではなく選択オプションで表のセルを表示する方法です。私はこのような私のページでオプションを選択するには、テーブルのセルを変換したい入力から、セルテーブル内で複数行を変換するオプションを選択する

Andy 
Alex 
John 
etc... 

ので:

<form method="post"> 
<textarea name="input"></textarea> 
<button type="submit" name="button">button</button> 
<table class="table table-bordered" id="tableAll"> 
<thead> 
<tr> 
    <th class="col-md-1">name</th> 
</tr> 
</thead> 
<tbody> 
    <tr> 
     <?php 
      if(isset($_POST['button'])) 
      { 
       echo "<td>".$_POST["input"]."</td>"; 
      } 
     ?> 
    </tr> 
</tbody> 
</table> 
</form> 

<style> 
    td { white-space:pre } 
</style> 

私はこのようなテキストエリアで入力された:

は、私は単純なコードを持っています:

<table class="table table-bordered" id="tableAll"> 
<thead> 
<tr> 
    <th class="col-md-1">name</th> 
</tr> 
</thead> 
<tbody> 
    <tr> 
     <select> 
      <option>Andy</option> 
      <option>Alex</option> 
      <option>John</option> 
      <option>etc...</option> 
     </select> 
    </tr> 
</tbody> 
</table> 

答えて

1

あなたは以下のようにそれを行うことができます: -

<?php 
    if(isset($_POST["input"])) 
    { 
     $select_data = explode("\n",$_POST["input"]); // explode input data with new line 
    } 

?> 
<?php if(count($select_data) >0){?> 
    <select> 
     <?php 
      foreach($select_data as $select_dat){?> 
      <option value = "<?php echo $select_dat;?>"><?php echo $select_dat;?></option> 
     <?php }?> 
    </select> 
<?php }?> 
関連する問題