473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Edit Drop down box values

250 100+
I want to edit database values using my web application. So first i load data to test boxex and drop down list. But drop down list only contain one value. I want to put all posible value to that and should high light particular one. (Because if user want to edit drop down box value)How can i do that?
Feb 13 '08 #1
4 6399
harshmaul
490 Expert 256MB
You will need to fill the drop down list with all the values, and then print selected in the drop down list if the value in the DB matches the one in the Drop Down list.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $valueFromDB = "apples";
  3. ?>
  4. <select>
  5. <?php
  6. $arr = array("please select", "apples", "pears", "grapes");
  7. foreach ($arr as $value) {
  8.     $selected= $value == $valueFromDB ? "selected" : "";
  9. ?>
  10. <option <?php echo $selected; ?>><?php echo $value; ?></option> 
  11. <?php
  12. }
  13. ?> 
  14. </select>
Feb 14 '08 #2
ghjk
250 100+
It is working ! Thanks
Feb 15 '08 #3
harshmaul
490 Expert 256MB
No worries. I'm here to help!
Feb 15 '08 #4
i tried ur code above.. it works for me to insert but it didn't retrieve the exact info from database.. what i mean is it only show the last dropdown value only

below is my code

<?php
$valueFromDB = "E1";
$valueFromDB = "E2";
$valueFromDB = "TM";
$valueFromDB = "TP";
?>
<select name="positiontype">
<?php
$arr = array("Select One", "E1","E2", "TM", "TP");
foreach ($arr as $row_rsXDsecondary['positiontype']){
// $row_rsXDsecondary['positiontype'] = $value;
$selected= $row_rsXDsecondary['positiontype'] == $valueFromDB ? "selected" : "";
?>
<option <?php echo $selected; ?>><?php echo $row_rsXDsecondary['positiontype']; ?></option>

}
<?php
}
?>
</select>
and it always show TP

thank you in advance
Oct 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first...
4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
4
by: Terren | last post by:
I need to be able to edit a drop down box is asp. On my web app I populate a drop down box from a databse. The user can then select an option that will then be saved to a Database for example Mr...
0
by: San Diego Guy | last post by:
Hi all! I have Datagrid. Within that datagrid I have a drop down list that I set up some values in (a "collection") I set up an edit command column on the datagrid and wrote simple code to get...
3
by: Tim::.. | last post by:
Can someone tell me how I get the correct selected office in my drop down list when I enter edit mode. At the moment it just defaults to the office at the top of the drop down list rather than...
8
by: sara | last post by:
I have a table where a few of the users entered vendor names ALL IN UPPER CASE. I have created forms to edit the data, but I can't seem to allow changing JOE SMITH to Joe Smith. What to I have...
4
by: _MC_ | last post by:
Hi, I'm unable to access values in my Datagrid. Datagrid thinks it hase only 1 Cell. So here it is: The Datagrid is binded in PageLoad, AutoGenerateColumns is false, Columns are added on...
5
by: agarwalsunitadhn | last post by:
hello I am using drop down in edit template instead of textbox. it runs properly bt problem is that when i click on the edit button then the selected value doesnt shown there, instead of 0th index...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.