Return table from mySQL with a selected option from the database value

user1190132

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!

Professor Abronsius

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to pull selected data from a table in a database

From Dev

Displaying selected option from database in a select option tag

From Dev

Fetch data from mysql database using drop down list and then use search function to filter data from selected drop down list option

From Dev

How to set radcombobox selected value from database?

From Dev

php populate option box from database table

From Dev

Get selected option value from specific select

From Dev

search the database based on the value selected from database

From Dev

Display selected results only from the database table

From Dev

Show Selected Value From Database Jquery

From Dev

how to set select option if selected on submit in ci ,options value fetching from the database?

From Dev

Selected specific option in dropdown based on data retrieved from database(mysql) with ng-option

From Dev

mysql insert with value, with selected data from another table

From Dev

Displaying selected option from database in a select option tag

From Dev

Mysql Replication for selected tables from a database?

From Dev

Selected just only one value option from several option

From Dev

How to set radcombobox selected value from database?

From Dev

how to choose table from a database that is selected with directory?

From Dev

Return Value Not Currently Assigned from MYSQL Database

From Dev

search the database based on the value selected from database

From Dev

Why the value from mysql database is not set as "selected" in the dropdown in PHP

From Dev

how to set select option if selected on submit in ci ,options value fetching from the database?

From Dev

Mysql - Return max value from joined table

From Dev

VBA return value from option button

From Dev

Read value from MySQL and compare which option is selected from drop-down list

From Dev

Get selected value from database table?

From Dev

MySQL function return value from row in table

From Dev

Retrieving selected option from a table cell

From Dev

Populate Selected option in options_for_select with boolean value from database

From Dev

Values selected from the database table returns nil

Related Related

  1. 1

    How to pull selected data from a table in a database

  2. 2

    Displaying selected option from database in a select option tag

  3. 3

    Fetch data from mysql database using drop down list and then use search function to filter data from selected drop down list option

  4. 4

    How to set radcombobox selected value from database?

  5. 5

    php populate option box from database table

  6. 6

    Get selected option value from specific select

  7. 7

    search the database based on the value selected from database

  8. 8

    Display selected results only from the database table

  9. 9

    Show Selected Value From Database Jquery

  10. 10

    how to set select option if selected on submit in ci ,options value fetching from the database?

  11. 11

    Selected specific option in dropdown based on data retrieved from database(mysql) with ng-option

  12. 12

    mysql insert with value, with selected data from another table

  13. 13

    Displaying selected option from database in a select option tag

  14. 14

    Mysql Replication for selected tables from a database?

  15. 15

    Selected just only one value option from several option

  16. 16

    How to set radcombobox selected value from database?

  17. 17

    how to choose table from a database that is selected with directory?

  18. 18

    Return Value Not Currently Assigned from MYSQL Database

  19. 19

    search the database based on the value selected from database

  20. 20

    Why the value from mysql database is not set as "selected" in the dropdown in PHP

  21. 21

    how to set select option if selected on submit in ci ,options value fetching from the database?

  22. 22

    Mysql - Return max value from joined table

  23. 23

    VBA return value from option button

  24. 24

    Read value from MySQL and compare which option is selected from drop-down list

  25. 25

    Get selected value from database table?

  26. 26

    MySQL function return value from row in table

  27. 27

    Retrieving selected option from a table cell

  28. 28

    Populate Selected option in options_for_select with boolean value from database

  29. 29

    Values selected from the database table returns nil

HotTag

Archive