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条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化