PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 31st, 2000, 01:37 AM
mouserdj mouserdj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 77 mouserdj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
I have a database of contacts setup... one of the options is for new people to add their own information to the database. So some of the fields (such as Department) are added via a drop down box of values. However, users also need to be able to edit their information at later dates... When they do edit their information, there current record is shown in editable text form elements. The problem I am having is: how can I make it so that when the users edit the information, the drop down box is already at the correct option. I have no problem with the stardard text boxes, its just the drop down boxes that are giving me grief. Please help me someone! Thanks

Dave

Reply With Quote
  #2  
Old May 31st, 2000, 05:27 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan
you can achive this very easily ,

i usually do like this.

i create a seperate table for Department.and save all my department names in that.

when i want to give the modify option to the user.it should populate all these values to the drop down menu.the value he already selected will be the selected value.

here is an example,

<?php

$result=mysql_query("select name,age,dept_name from usertable where username='shiju',$con);
//query for displaying your user information.

$row=mysql_fetch_array($result);

$result1=mysql_query("select dept_name from depertament",$con);

//Query for populating all the department name to the drop down menu.


?>

<select name="dept">

<?

do{
if($sec_query_row["dept_name"]!= $row["dept_name"]){
echo "<option value=".$sec_query_row["dept_name"].">".$sec_query_row["dept_name"]."</option>";

// if dept name is already not selected then simply populate values to the drop down(ie, values that is not selected).

}else{

//else if it is selected then populate to the drop down menu and make it as selected.

echo "<option value=".$row["dept_name"]." selected>".$row["dept_name"]."</option>";

}
}while($sec_query_row=mysql_fetch_array($result1));
// Rotate the loop till popualting all the values to the drop down.

?>
</select>


#######-- This will solve your problem.i normally do like this. But you can save all the department names in an array and do same kind of action.

#################-------#################
One advantage using table is that you can update that table any time and that will populate value to the drop down menu insetead of changing the array value in your script.

################--------

i hope you have understood the logic.if any problem tell me here!!


Good Luck!!


------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

[This message has been edited by Shiju Rajan (edited May 31, 2000).]

Reply With Quote
  #3  
Old May 31st, 2000, 06:03 PM
mouserdj mouserdj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 77 mouserdj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Thanks for the help, I have it working, it is displaying items from my database in a drop down box, however I changed it to use the current table. I don't want to start using multiple tables because then it may complicate what is supposed to be a relatively simple application.

One problem I am having though, is items are appearing more than once. Say there are 2 people in the IT department, then my drop down box is having two items. Also the current item is not selected!! Can you help me with this?? Thanks in advance.

Dave

Reply With Quote
  #4  
Old May 31st, 2000, 06:32 PM
mouserdj mouserdj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 77 mouserdj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Actually on second thoughts, I did add the departments to another table. That part works well. The only problem I am having at the moment is that my desired item is not selected. I don't think the script actually specifies it... however I am unsure as I am only new to php. Can you help?? Here is the script that I modified (i am now looking for location). I have a new table setup called location.

<?php

$result1=mysql_query("select location from location",$db);

//Query for populating all the department name to the drop down menu.
?>

<select name="location">
<?php

do{
if($sec_query_row["location"]!= $row["location"]){
echo "<option value=".$sec_query_row["location"].">".$sec_query_row["location"]."</option>";

// if dept name is already not selected then simply populate values to the drop down(ie, values that is not selected).

}

else

{

//else if it is selected then populate to the drop down menu and make it as selected.

echo "<option value=".$row["location"]." selected>".$row["location"]."</option>";

}
} while($sec_query_row=mysql_fetch_array($result1));
// Rotate the loop till popualting all the values to the drop down.

// End drop box section
?>
</select>

Note: I don't have the initial select statement that you specified as the array is already passed to the page to begin with. So there was no need to search for a users details.

Thanks in advance.

Dave

Reply With Quote
  #5  
Old May 31st, 2000, 07:54 PM
mouserdj mouserdj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 77 mouserdj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Cancel those last two posts... however my latest problem is that some of the items in the table have space in them. eg "District Manager". When i select these one from the box and click update... it only adds the first part ("District"). Therefore, next time you view the persons records nothing comes up as it doesn't match the drop-down box options. How do I pass the value including any spaces.

Oh, I fixed the problem because I had it call $row[location] when it should have been $myrow[location]. Thanks again for your help.

Dave

Reply With Quote
  #6  
Old May 31st, 2000, 11:20 PM
mouserdj mouserdj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Posts: 77 mouserdj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Cancel the final one as well , I was a bit too quick off the mark. After a couple of hours or trying different things, I finally worked out that I needed to format the results in printf's rather than print or echo. That way it retains the formatting. Thank you very much for your help though, it was invaluable.

Regards

Dave

Reply With Quote
  #7  
Old June 1st, 2000, 12:18 AM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

Welcome Mr.Dave!!



------------------
SR -
shiju.dreamcenter.net

"The fear of the LORD is the beginning of knowledge..."

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Passing values to drop down box...

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap