I can use some help here. I have page where a user can make updates to a DB record. The user can then select items from a drop down list. I'm trying to get my drop down list to pull from the MySQL and have the value that is stored in MySQL be the one selected in the option selected tag <option selected value="$rating"> . So if the user does not edit this field the original value remains unchanged.

For example:
<select>
        <option selected value='$rating'>
        <option> All the other options to choose from</option>
</select>

The tricky part is the actual value, in this case the ($rating) is stored in a table called routes. The options which I want in the drop down list are stored in a table called ranking. Both tables have a rating column.

My apologies if this is not clear, its gets confusing trying to explain it. Any help anyone can give would be great. Thanks - CH

Here is my code snippet:
The drop down list is marked with  //Drop Down List

<?php
if($_POST["postback_edit_private_results"]);
                {
                include "include/db.php";     

$route_count = $_POST["route_count"];
$username = $_POST["username"];
$user_id = $_POST["user_id"];
$fall = $_POST["fall"];
$rating = $_POST["rating"];

$query = "SELECT * FROM users, routes, ranking WHERE route_count = '$route_count' AND username='$username' AND routes.rating = ranking.rating';
echo $query;
$result = mysql_query($query,$db) or die(mysql_error());
if ($row = mysql_fetch_array($result))

{
echo ("<form method='post' action='confirm_receipt.php' encType='multipart/form-data'>");
echo ("<table cellspacing='0' cellpadding='3' border='1' id='upload_table'>
<tr id='alt_3'>
<td>* Route:</td>
<td><input type='text' name='route' size='20' value='$row[route]'></td>
</tr>
<tr id='alt_2'>
<td>* Area:
<br />i.e: Yosemite</td>
<td><input type='text' name='area' size='20' value='$row[area]'></td>
</tr>
<tr id='alt_3'>
<td>* Crag:
<br />i.e.: Half Dome</td>
<td><input type='text' name='outcrop' size='20' value='$row[outcrop]'></td>
</tr>
<tr id='alt_2'>
<td >Current Rating:</td>
<td> <select name='rating'>");
//Drop Down List
$rating = $_POST['rating'];


                    $options .="<option value=\"$rating\"";

                        if ($_POST['rating'] == "$rating") {
                        $options .=" selected=\"selected\"";
                        }

                    $options .=">$rating</option>\n";

    echo $options;
    echo("</select></td>");

The rest of the page...

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to