Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Update; old and new data

Status
Not open for further replies.

sipps

Technical User
Feb 9, 2003
133
GB
Hi all,

I have a page where users can select a car for example, and this will bring up the next screen where they can edit that specific cars details. Problem is, I have drop downs for some of the criteria such as Auto/Manual, Petrol/Diesel. If I have static values in these menus then when you first get to the page, it will be incorrect if the car was a Diesel, not Petrol.

If I dynamically link a drop down to the db, and bring up the actual value for that car, then I cannot select anything else in the drop down unless I put static values in there again. This causes repeated data, such as Petrol/Diesel/Petrol.

Is there any way that I can dynamically get the value into the dropdown, and get values that are possible for that category but not repeating the data in anyway, so if the car is Petrol, it gets this from the db, and also puts in Diesel as another option?

Thanks!
 
Sorry sleipnir214,

There are no values listed in the db, like Number_Doors is just an int, so only one number can be stored at any one time. So one car may have 2 doors, but someone might want to change this to 4, but if I put all the possible doors in statically, I repeat 2 again.

But your example may work for another category where I can select the available locations for a car. I tried doing the Select all locations from the location table, and adding these to the drop down, and then setting the initial value to the Location stored in the vehicle table, but it still just brings up the first location I selected from the location table.
I used two connections, one to get a list of locations from the location table, and the other to get the actual location from the vehicle table:

<select name=&quot;Location_Name&quot;>
<?php
do {
?>
<option value=&quot;<?php echo $row_getlocation['Location_ID']?>&quot;<?php if (!(strcmp($row_getlocation['Location_ID'], $row_adminmodcar['Location_Name']))) {echo &quot;SELECTED&quot;;} ?>><?php echo $row_getlocation['Location_Name']?></option>
<?php
} while ($row_getlocation = mysql_fetch_assoc($getlocation));
$rows = mysql_num_rows($getlocation);
if($rows > 0) {
mysql_data_seek($getlocation, 0);
$row_getlocation = mysql_fetch_assoc($getlocation);
}
?>

Any thoughts?
Cheers
 
Why are you outputting the first <OPTION> element before you fetch any data from MySQL? A do{}while() construct runs the internal code block one time before the condition is ever checked.

And I have no idea what the if-block following your do loop is supposed to do.

Here's how I would do it:
-Fetch the data for a particular car.
-For any given attribute for a car, fetch the unique values for the attribute.
-Loop through the attribute values, outputting them in OPTION tags of a SELECT tage. When you get to the attribute that matches your car's current value, issue &quot;SELECTED&quot;.
-Output a hidden field which contains the car's current value.
-The script that would perform an update should see whether the user changed the value. If not, it should not perform the update. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top