|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Pulldown Menu
Hey Everyone,
I could use some help here. I have a page where a user clicks "edit" to make changes/updates to thier profile. On the "edit" page there are several drop down menu's (<select> and <option>)where the user can change certain things. When the user comes to this page I would like the pulldown down menu to show the current value that's stored in MySQL and then the rest of the options. If the user does not edit this field the current value remains and nothing is updated. Does this make any sense? Any help would be great! Here is my code: $query = "SELECT ranking.*, routes.* FROM ranking, routes WHERE routes.rating = ranking.rating GROUP BY id ORDER BY id"; echo $query; $result = mysql_query($query2, $db); if ($row = mysql_fetch_array($result)) { do { $rating = $row['2']; $id = $row['1']; $option .= "<optionvalue='$id' selected='$row[2]'>$rating</option>"; } while($row = mysql_fetch_array($result)); echo ("<td colspan='3'> <select name='rating'> $option </select> </td> "); } |
|
#2
|
|||
|
|||
|
Try this..Hope it's help.
<tr> <td> <select name="rating"> <?php $query = "SELECT ranking.*, routes.* FROM ranking, routes WHERE routes.rating = ranking.rating GROUP BY id ORDER BY id"; //echo $query; $result = mysql_query($query, $db); while($row = mysql_fetch_array($result)) { $rating = $row['2']; $id = $row['1']; //Assume that variable $value is the key to present the rating is a current selected value in db //You also can query it in your sql statement $value=$row['value in db']; if($value=='$id') { echo "<option selected value='$id'>$rating</option>\n"; } else { echo "<option value='$id'>$rating</option>\n"; } } ?> </select> <td> </tr> |
|
#3
|
|||
|
|||
|
Cool Thanks. I have it pulling the correct value from the MySQL. The problem I'm having is it doesn't show the "other" values to choose from. Here is a snap shot of the source code. I think you will see what I mean.
<select name='rating'> <option value='3rd Class'>5.8</option> <option value='4th Class'>5.8</option> <option value='5.0'>5.8</option> <option value='5.1'>5.8</option> <option value='5.2'>5.8</option Here's my query: $query = "SELECT * FROM users, routes, ranking WHERE route_count = '$route_count' AND username='$username' AND users.user_id = routes.user_id "; Any help would be a great help. Thanks. |
|
#4
|
|||
|
|||
|
If i understood you correctly, add the <option> in your while loop
|
|
#5
|
|||
|
|||
|
Quote:
Or is it the selected value was not been chosen in that list?? |
|
#6
|
|||
|
|||
|
Sorry for not being clear last night. Basically, I can get the currect value from MySQL in the select / option menu. The problem is I can not get the other fields to appear in case the user wants to change something. Here is my code:
$query = "SELECT * FROM users, routes, ranking WHERE route_count = '$route_count' AND username='$username' "; 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'>"); $rating = $row['16']; $id = $row['31']; if ($value =='$id') { echo "<option selected value='$id'>$rating</option>\n"; } else { echo "<option value='$id'>$rating</option>\n"; } echo("</select> </td>"); } } } ?> |
|
#7
|
||||
|
||||
|
Quote:
I think your sql statement is specific to selected option only.In that case you gonna make your sql more genaral. Maybe,it's like this because i don't know the description of your table Quote:
I hope it make sense. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Dynamic Pulldown Menu |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|