dongwei7913 2015-11-07 14:54
浏览 21
已采纳

使用数据库值中的选定选项从mySQL返回表

I am writing a task management website in php that returns a mySQL table; the main meat of this is shown below:

echo "<tr><td>" . $formatissuedate . "</td>" . "<td>" . $row["issuer"] . "            </td>" . "<td>" . $row["task"] . "</td>" . "<td>" . $row["responsibility"] . "</td>" . "<td>" . $formatduedate . "</td>" . "**<td>" . $row["status"] . "</td>**    </tr>";

However what I would like to do is for the: <td>" . $row["status"] . "</td> area is to have a drop down which contains the options="completed","started" and "not started" and for the selected option to be the value from mySQL ($row["status"]).

I have no idea how to do this. Once I get this sorted out I will write some jquery so that when this value changes to write back to the mySQL database with the updated value. Your help is much appreciated!

  • 写回答

3条回答 默认 最新

  • dougourang1856 2015-11-07 15:04
    关注

    Something like below ought to give you some idea how to proceed. If these records are created within a loop ( ie: recordset iteration ) then you can define the array $options before the loop starts.

    <?php
        /* Assume this is in a loop? Also, assumed a record called `id` */
        $status=$row['status'];
        $options=array('completed','started','not started');
    
        echo "
            <tr>
                <td>" . $formatissuedate . "</td>
                <td>" . $row["issuer"] . "</td>
                <td>" . $row["task"] . "</td>
                <td>" . $row["responsibility"] . "</td>
                <td>" . $formatduedate . "</td>
                <td>
                    <select name='status_{$row['id']}'>";
    
        foreach( $options as $key ){
            $selected=( $key==$status ) ? 'selected' : '';
            echo "<option value='{$key}'{$selected}>{$key}";    
        }
    
        echo "          
                    </select>
                </td>
            </tr>";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!