Ads Inside Post

Search in This Blog

Better way to fill select box in php

Problem:

Better way to fill select box in php

Solution:

Use Heredoc as below example

Example:

Assuming that $rs_list is the query result.
<?php
$list_trans="";
foreach ($rs_list->result() as $row_list) {
        $nm= $row_list->nm;
        $id=$row_list->id;
       
$list_trans.= <<<ABC
<option value="$id">$nm</option>
ABC;
    }
 ?>

    <select name="transporter_id">
            <?php echo $list_trans;?>
            </select>