acctman Posted October 6, 2008 Share Posted October 6, 2008 I hope I can explain this correctly. I have a user edit page that will retrieve info such ass Month, Day, Year, etc... for a user. My problem is how do I reinsert the value into the Select drop down menu. I set <%m_month%> as a variable it holds the users Month from the database, the value will be a digit 1-12. As you can see my select drop down menu has user digits for the value and text for the months. My question is how do I write a short fast code to take the value of <%m_month%> and associate it with the correct month and have it marked as Selected? code would be something like this I guess, this is just to show you what i'm trying to do if <%m_month%> == "" { echo '<OPTION value="" selected>Month</option>'; } else { echo '<OPTION value="<%m_month%>">FILL IN MONTH NAME</option>'; SHOW THE REST OF THE OPTIONS } <select name=add[month]> <OPTION value="" selected>Month</option> <OPTION value="1">January</option> <OPTION value="2">Feburary</option> <OPTION value="3">March</option> <OPTION value="4">April</option> <OPTION value="5">May</option> <OPTION value="6">June</option> <OPTION value="7">July</option> <OPTION value="8">August</option> <OPTION value="9">September</option> <OPTION value="10">October</option> <OPTION value="11">November</option> <OPTION value="12">December</option> </select> Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 6, 2008 Share Posted October 6, 2008 $months = array( 1 => 'January', 2 => 'February', 3 => 'march', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'Octobner', 11 => 'November', 12 => 'December' ); echo "<select name=\"add[month]\">\n"; foreach ($months as $month_id => $month_name) { $selected = ($m_month == $month_id) ?' selected="selected"':''; echo "<optiojn value=\"$month_id\">$month_name</option>\n"; } echo "</select>\n"; Quote Link to comment Share on other sites More sharing options...
acctman Posted October 6, 2008 Author Share Posted October 6, 2008 $months = array( 1 => 'January', 2 => 'February', 3 => 'march', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'Octobner', 11 => 'November', 12 => 'December' ); echo "<select name=\"add[month]\">\n"; foreach ($months as $month_id => $month_name) { $selected = ($m_month == $month_id) ?' selected="selected"':''; echo "<optiojn value=\"$month_id\">$month_name</option>\n"; } echo "</select>\n"; how would I apply <%m_mouth%> to the coding above? Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 6, 2008 Share Posted October 6, 2008 What is <%m_month%> exactly? You stated it was a variable, so I thought you had incorrecty typed that and you really meant that <%m_month%> was a variable such as $m_mouth (which is what I included in the code above). $selected = ($m_month == $month_id) ?' selected="selected"':''; If it's a constant then use it as such $selected = (m_month == $month_id) ?' selected="selected"':''; Quote Link to comment Share on other sites More sharing options...
acctman Posted October 6, 2008 Author Share Posted October 6, 2008 What is <%m_month%> exactly? You stated it was a variable, so I thought you had incorrecty typed that and you really meant that <%m_month%> was a variable such as $m_mouth (which is what I included in the code above). $selected = ($m_month == $month_id) ?' selected="selected"':''; If it's a constant then use it as such $selected = (m_month == $month_id) ?' selected="selected"':''; its a variable it holds the number value from the database for the users month. if I echo <%m_month%> for the testuser I'll receive a value of 2 (i.e February). Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 6, 2008 Share Posted October 6, 2008 Okay, this <%m_month%> has no meaning to me. I would assume it would either be a variable such as $m_month or a constant such as m_month. What are the tags <% and %> supposed to represent? I've never seen that before. Show me how you would echo that in your code. Quote Link to comment Share on other sites More sharing options...
acctman Posted October 6, 2008 Author Share Posted October 6, 2008 Okay, this <%m_month%> has no meaning to me. I would assume it would either be a variable such as $m_month or a constant such as m_month. What are the tags <% and %> supposed to represent? I've never seen that before. Show me how you would echo that in your code. a .tpl template file holds both HTML/CSS and PHP in order for the site to process global variables and constants, <% %> is used to distinguse it within php code or html code. so pretty much <%m_month%> can be echoed / insert anywhere on the site and it would return the value for that user. a parser.php file handles the processing of the var and const. m_user, m_age, m_city, m_day, m_year, etc... its OO but not standard why. Every user value from the database can easily be retrieved by inserting the db field name from the member table in between <% %> to echo the value within php you would do the following below. if you're in a .tpl file with html coding you'd just type <%m_month%>. it does all the sql lookup for you. echo <%m_month%>; // testuser value would be "2" Quote Link to comment Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Share Posted October 6, 2008 I take it you're using something like Mambo that uses a template system like that? Quote Link to comment Share on other sites More sharing options...
acctman Posted October 6, 2008 Author Share Posted October 6, 2008 I take it you're using something like Mambo that uses a template system like that? Yes, its like Mambo. Its actually an old image rating community script that i've pretty much recode with the help of other programmers on forums. all thats left is to re-populate the drop down menu with the correct selected value for editing and getting tinymce to work correctly Quote Link to comment Share on other sites More sharing options...
acctman Posted October 6, 2008 Author Share Posted October 6, 2008 any idea how i can plug <%m_month%> into the code Quote Link to comment Share on other sites More sharing options...
acctman Posted October 7, 2008 Author Share Posted October 7, 2008 ok I think I figured it out, $selected was never added to the echo and I just inserted <%m_month%> so far everything looks good <?php $months = array( 1 => 'January', 2 => 'February', 3 => 'march', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'Octobner', 11 => 'November', 12 => 'December' ); echo "<select name=\"add[month]\">\n"; foreach ($months as $month_id => $month_name) { $selected = (<%m_month%> == $month_id) ?' selected="selected"':''; echo "<option value=\"<%m_month%>\" $selected>$month_name</option>\n"; } echo "</select>\n"; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 7, 2008 Share Posted October 7, 2008 ??? I don't have a clue as to why that would work, but if it does, so be it. I was going to suggest creating the entire select list as a string variable within php and then include that variable in your template. 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.