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!
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>";
?>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments