Page 1 of 1
getting previously stored data in form before submitting
Posted: Fri Nov 13, 2009 4:39 pm
by chris_s_22
How do i get previous stored data from the database and display it in the feild
As you can see i can do it for text boxes and textarea
Code: Select all
Feild1:<input type="text" size="20" maxlength="20" name="feild1" value="<?php echo $feild1?>" align="" tabindex=""><br>
Feild2:<textarea name="feild2" cols="20" rows="5" tabindex=""><?php echo $feild2?></textarea><br>
but how would i do it for a drop down menu
Code: Select all
Feild3:
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
Re: getting previously stored data in form before submitting
Posted: Fri Nov 13, 2009 6:04 pm
by McInfo
It's much the same, except that the values are stored in an
array and the <option>s are written in a loop (
while, do-while, for, foreach).
Please use
.
Edit: This post was recovered from search engine cache.
Re: getting previously stored data in form before submitting
Posted: Fri Nov 13, 2009 6:14 pm
by chris_s_22
im still a bit confused any chance you could do a demonstration
like how it would work in this situation.say i already queried the data base and put result in
$sex
<select name="sex">
<option value="1">male</option>
<option value="2">female</option>
</select>
Re: getting previously stored data in form before submitting
Posted: Fri Nov 13, 2009 7:02 pm
by McInfo
I could, but I'm not sure that would help. I proposed
tags and that didn't help.
I'm sure you can figure it out if you spend a few more minutes reading through the examples in the manual.
Make a test script with a hard-coded array and write a loop to iterate through the array. I will help if you have trouble, but I need see some effort from you first.
Edit: This post was recovered from search engine cache.
Re: getting previously stored data in form before submitting
Posted: Sat Nov 14, 2009 7:34 am
by chris_s_22
Im sorry really dont understand what you mean by
could you point me in direction of a turtorial that explains the logic and covers this
i know how to select a feild and i know how to get data and display it like so
Code: Select all
Feild3:
<OPTION selected value="<?php echo $feild3?>"><?php echo $feild3?></OPTION>
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
However this method would mean that when the user came to change it, the data from database would display preselected at top but would also appear again in the list.
a work arround this would just to put a extra 1 or 2 feilds like so
Code: Select all
<option value="0"></option>
<option value="0">----------</option>
not exactly what i wanted but my best solution so far
Re: getting previously stored data in form before submitting
Posted: Sat Nov 14, 2009 1:27 pm
by McInfo
You need to query the database and retrieve a list of values and labels that will fill the <option>s in the <select>. While looping through the rows, compare the current row value to the user-selected value. If they match, give the <option> a selected="selected" attribute.
Related topic: (broken)
103335
chris_s_22 wrote:Im sorry really dont understand what you mean by
If you read your post after posting it, you might have noticed that
was converted into a code box. The difference between that code box and one created with plain
tags is that the HTML code box syntax-highlights HTML within it.
Plain BBCode code tags:
Code: Select all
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
HTML BBCode code tags:
Code: Select all
<select name="feild3">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
Edit: This post was recovered from search engine cache.