PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 3rd, 2004, 06:08 PM
m0untaind0g m0untaind0g is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 18 m0untaind0g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via AIM to m0untaind0g
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> ");
}

Reply With Quote
  #2  
Old October 3rd, 2004, 09:08 PM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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>

Reply With Quote
  #3  
Old October 3rd, 2004, 10:58 PM
m0untaind0g m0untaind0g is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 18 m0untaind0g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via AIM to m0untaind0g
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.

Reply With Quote
  #4  
Old October 4th, 2004, 12:42 AM
xlordt xlordt is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: 127.0.0.1
Posts: 20 xlordt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 m 39 sec
Reputation Power: 0
Send a message via ICQ to xlordt Send a message via AIM to xlordt Send a message via MSN to xlordt Send a message via Yahoo to xlordt
If i understood you correctly, add the <option> in your while loop

Reply With Quote
  #5  
Old October 4th, 2004, 12:50 AM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
The problem I'm having is it doesn't show the "other" values to choose from.
What is your mean?? I guess the problem that u have is your query. If u want the drop menu list all the values u gonna make your query more genaral.

Or is it the selected value was not been chosen in that list??

Reply With Quote
  #6  
Old October 4th, 2004, 06:09 AM
m0untaind0g m0untaind0g is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 18 m0untaind0g User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 42 m 10 sec
Reputation Power: 0
Send a message via AIM to m0untaind0g
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>");

}
}
}
?>

Reply With Quote
  #7  
Old October 4th, 2004, 08:44 PM
eddynazrul eddynazrul is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: 192.168.1.4
Posts: 21 eddynazrul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
The problem is I can not get the other fields to appear in case the user wants to change something.

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:
$query="SELECT routes FROM routes";

I hope it make sense.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Dynamic Pulldown Menu


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT