depojones Posted April 29, 2010 Share Posted April 29, 2010 Hi all, I have a member registration page that allow users to edit their profile. How do i retrieve a value and insert it to a radio button or a select menu. At the moment, i can only populate into a text field or a textarea. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 29, 2010 Share Posted April 29, 2010 Try setting the value of the radio button to a variable to recieve data from a form. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted April 29, 2010 Share Posted April 29, 2010 You've not shown how you are retrieving it, or even how the data is stored (flatfile, database etc). The radio is just as simple as <input type="radio" name="radio_group_id_here" value="<?php echo $value; ?>" /> Text here of radio button Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 Thanks for the reply. Here is the scenario: am retrieving values from the database like this: $rs_settings = mysql_query("select gender from users_tbl where userid='$_SESSION[uSER_ID]'"); while ($row = mysql_fetch_array($rs_settings)) { <html> <title>test</title> <head></head> <body> Gender: Male <input type="radio" name="gender" value="Male" /> Female <input type="radio" name="gender" value="Female" /> </body> </html> All I need to do is to retrieve what the user chose during registration. Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 I can explain better if my explanation is not sufficient Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 29, 2010 Share Posted April 29, 2010 So if the result from the query = male you want the male radio button checked? 1 = male, AND 0 = female Then you could do: if($gender == 1) { echo <<<_END Male <input type="radio" name="gender" value="Male" checked="checked" /> Female <input type="radio" name="gender" value="Female" /> _END; } elseif($gender == 0) { echo <<<_END Male <input type="radio" name="gender" value="Male" /> Female <input type="radio" name="gender" value="Female" checked="checked" /> _END; } Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 Worked like a charm! Thanks for your contribution. I have a question though, am trying to use the same logic for a select option menu. I have a select menu for DAY | MONTH | YEAR, do I have to use the conditional statement for every value or there is a simpler way to do this. Maybe an array() or something related. Take a look: <select name="ddYear" id="ddYear"> <option value="1909">1909</option> <option value="1910">1910</option> <option value="1911">1911</option> <option value="1912">1912</option> <option value="1913">1913</option> <option value="1914">1914</option> <option value="1915">1915</option> <option value="1916">1916</option> <option value="1917">1917</option> <option value="1918">1918</option> <option value="1919">1919</option> <option value="1920">1920</option> <option value="1921">1921</option> <option value="1922">1922</option> <option value="1923">1923</option> <option value="1924">1924</option> <option value="1925">1925</option> <option value="1926">1926</option> <option value="1927">1927</option> <option value="1928">1928</option> <option value="1929">1929</option> <option value="1930">1930</option> <option value="1931">1931</option> <option value="1932">1932</option> <option value="1933">1933</option> <option value="1934">1934</option> <option value="1935">1935</option> <option value="1936">1936</option> <option value="1937">1937</option> <option value="1938">1938</option> <option value="1939">1939</option> <option value="1940">1940</option> <option value="1941">1941</option> <option value="1942">1942</option> <option value="1943">1943</option> <option value="1944">1944</option> <option value="1945">1945</option> <option value="1946">1946</option> <option value="1947">1947</option> <option value="1948">1948</option> <option value="1949">1949</option> <option value="1950">1950</option> <option value="1951">1951</option> <option value="1952">1952</option> <option value="1953">1953</option> <option value="1954">1954</option> <option value="1955">1955</option> <option value="1956">1956</option> <option value="1957">1957</option> <option value="1958">1958</option> <option value="1959">1959</option> <option value="1960">1960</option> <option value="1961">1961</option> <option value="1962">1962</option> <option value="1963">1963</option> <option value="1964">1964</option> <option value="1965">1965</option> <option value="1966">1966</option> <option value="1967">1967</option> <option value="1968">1968</option> <option value="1969">1969</option> <option value="1970">1970</option> <option value="1971">1971</option> <option value="1972">1972</option> <option value="1973">1973</option> <option value="1974">1974</option> <option value="1975">1975</option> <option value="1976">1976</option> <option value="1977">1977</option> <option value="1978">1978</option> <option value="1979">1979</option> <option value="1980">1980</option> <option value="1981">1981</option> <option value="1982">1982</option> <option value="1983">1983</option> <option value="1984">1984</option> <option value="1985">1985</option> <option value="1986">1986</option> <option value="1987">1987</option> <option value="1988">1988</option> <option value="1989">1989</option> <option value="1990">1990</option> <option value="1991">1991</option> This list is just too long to be using an if statement. Please help Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 29, 2010 Share Posted April 29, 2010 Quite new to php my self so don't know off the top of my head how to get the current year, but this will work (i think) from 1909-2010. You'll have to pardon the long winded "echo <<<_END..._END;", i've just got used to using them over the past few weeks: for($year = 1909 ; $year < 2010 ; ++$year) { echo <<<_END <option value="$year">$year</option> _END; } Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 @Freelance, my point is this: user x chose 1995 as his date of birth during registration, now I want to display the 1995 to the user on his edit profile page. The year(1995) must be in a drop down menu with other years, but ofcourse the 1995 will be selected. How do i go about this. Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 29, 2010 Share Posted April 29, 2010 I'm really not too sure what you after here... user x: D.O.B = 1995 and can be pulled from the members table in MySQL? That can be then displayed anywhere once you've got it into a variable. But then you want the to have a list/menu on the page which when selected the users DOB is highlighted? Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 Take a look at this: I want users to be able to edit their information. So let's say user x DOB is 1995(the year he was born) and he wanna change it to 1985 how can I achieve this? The possible solution is: creating a drop down menu where user x can select the new year (which is 1985) from isn't. So my question is: In a dropdown menu, how can the year which is 1995 be selected automatically. Thats all Quote Link to comment Share on other sites More sharing options...
freelance84 Posted April 29, 2010 Share Posted April 29, 2010 $dob = (value taken from database or wehere ever it is stored) for($year = 1909 ; $year < 2010 ; ++$year) { if($year == $dob) { echo <<<_END <option value="$year" selected = 'selected'>$year</option> _END; } else { echo <<<_END <option value="$year">$year</option> _END; } } didn't know you could preselect options from a drop down menu! Awesome! Quote Link to comment Share on other sites More sharing options...
depojones Posted April 29, 2010 Author Share Posted April 29, 2010 Thank you for your post Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.