php - How do I echo selected in a while loop? -


There are a blog and question sections on my site, which contain categories when a user creates a question or a blog, a drop down The menu that allows you to choose your category. When you edit one of these, you have the option to change your category through the dropdown. When you edit a blog, the category drop down is a standard style dropdown, and I have the & lt; Option value = "1" & lt; Php if ($ blog- & gt; category == "1") {echo "selected";}? & Gt; & Gt; Art & Literature & lt; / Option & gt; I'm picking up to show the pre-selected category where another developer has been left out, so for the question that has been down in the loop. Being a newbie I do not know how to "selectively select" in the loop to pull the last chosen cat. Here is the loop

  & lt; Select name = "category" & gt; & Lt; Option value = "zero" & gt; Select category & lt; / Options & gt; & Lt ;? Php $ query = "class_name" ASC "classified_selected order; $ Request = mysql_query ($ query, $ connection); While ($ result = mysql_fetch_array ($ request)) {echo "option value = '". $ Result ['id'] "'' & gt; . $ Result ['classname'] "& lt; / option & gt;"; }? & Gt; & Lt; / Select & gt;  

You can do it the same way, assume that you have a $ blog object Where this code is undergoing:

  while ($ result = mysql_fetch_array ($ request)) {$ selected = ($ result ['id'] == $ blog- & gt; category) ? 'Selected =' selected '': ''; Echo "& lt; option value = ''. $ Result ['id']" '". $ Selected." & Gt; $. [' Category '] "& lt; / Option & gt; ";}  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -