php dropdown menu remembers selected option

Reply

Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

php dropdown menu remembers selected option

 
0
  #1
Apr 29th, 2009
i have this code

  1. <body>
  2. <?php
  3. include 'cms/core/config.php';
  4. include 'cms/core/opendb.php';
  5.  
  6. $query = "SELECT id, language, updated ". "FROM meta ". "WHERE id = '5'";
  7. $result = mysql_query($query) or die('Error : ' . mysql_error());
  8. list($id, $language, $updated) = mysql_fetch_array($result, MYSQL_NUM);
  9.  
  10. include 'cms/core/closedb.php';
  11. ?>
  12. <form method="post" action="default.php?s=editmeta">
  13. <input type="hidden" name="id" value="5">
  14. <table width="700" border="0" cellpadding="5" cellspacing="0" class="box">
  15. <tr>
  16. <td width="100" valign="top">Language:</td>
  17. <td>
  18. <select name='language' id="language" >
  19. <option value="bg">Bulgarian</option>
  20. <option value="cs">Czech</option>
  21. <option value="da">Danish</option>
  22. <option value="de">German</option>
  23. <option value="el">Greek</option>
  24. <option value="en" selected>English</option>
  25. <option value="en-gb">English (UK)</option>
  26. <option value="en-us">English (US)</option>
  27. <option value="es">Spanish</option>
  28. <option value="fi">Finnish</option>
  29. <option value="hr">Croatian</option>
  30. <option value="it">Italian</option>
  31. <option value="fr">French</option>
  32. <option value="fr-ca">French (Quebec)</option>
  33. <option value="ja">Japanese</option>
  34. <option value="ko">Korean</option>
  35. <option value="nl">Dutch</option>
  36. <option value="no">Norwegian</option>
  37. <option value="pl">Polish</option>
  38. <option value="ru">Russian</option>
  39. <option value="sv">Swedish</option>
  40. <option value="zh">Chinese</option>
  41. </select> </td>
  42. </tr>
  43. <tr>
  44. <td colspan="2" align="center"><input name="update" type="submit" id="update" value="Update Content"></td>
  45. </tr>
  46. </table>
  47. </form>
  48. </body>
  49. </html>

basically before this page i have another to post your selected language to the db. the page pasted below is the edit page where you can you can change your language. what i want is that if in the first page you choose danish for instance and then you want go to change it at al later time it remembers that you had choosen danish.

i think i had found a script but couldnt understand how to implement it as im still green in php the script im talking about is in the following:

  1. <?php
  2. $link=mysql_pconnect("localhost","user","password");
  3. mysql_select_db("db",$link);
  4. $result = mysql_query("select date_format(birth_date,'%Y') as birth_year from members where member_id=1");
  5.  
  6. $row=mysql_fetch_array($result); // fetch first row
  7. $year=$row["birth_year"]; // retrieve 4-digit year of birth
  8.  
  9. // display combo: current year -> -100
  10. $current_year=date("Y");
  11. echo '<select name="cbo_year">';
  12. for ($i = $current_year; $i >= ($current_year-100); $i--) {
  13. echo '<option '.($year == $i ? ' selected ' : '').' value="'.$i.'" >'.$i.'</option>';
  14. }
  15. echo '</select>';
  16. ?>

just for you to know the table name is meta and the field is language. i will be glad if somebody help me out as im really stuck on this one! thanks alot in advance guys!
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: php dropdown menu remembers selected option

 
0
  #2
Apr 29th, 2009
I hope this example will give you a better idea.
  1. <html>
  2. <body>
  3. <form method="post" name="form1">
  4. <select name="location">
  5. <option value="city1" <?php if($_REQUEST['location']=="city1") { echo "selected"; }?>>City1</option>
  6. <option value="city2" <?php if($_REQUEST['location']=="city2") { echo "selected"; }?>>City2</option>
  7. <option value="city3" <?php if($_REQUEST['location']=="city3") { echo "selected"; }?>>City3</option>
  8. <option value="city4" <?php if($_REQUEST['location']=="city4") { echo "selected"; }?>>City4</option>
  9. <option value="city5" <?php if($_REQUEST['location']=="city5") { echo "selected"; }?>>City5</option>
  10. </select>
  11. <input type="submit" name="submit" value="submit">
  12. </form>
  13. </body>
  14. </html>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: php dropdown menu remembers selected option

 
0
  #3
Apr 29th, 2009
Originally Posted by nav33n View Post
I hope this example will give you a better idea.
  1. <html>
  2. <body>
  3. <form method="post" name="form1">
  4. <select name="location">
  5. <option value="city1" <?php if($_REQUEST['location']=="city1") { echo "selected"; }?>>City1</option>
  6. <option value="city2" <?php if($_REQUEST['location']=="city2") { echo "selected"; }?>>City2</option>
  7. <option value="city3" <?php if($_REQUEST['location']=="city3") { echo "selected"; }?>>City3</option>
  8. <option value="city4" <?php if($_REQUEST['location']=="city4") { echo "selected"; }?>>City4</option>
  9. <option value="city5" <?php if($_REQUEST['location']=="city5") { echo "selected"; }?>>City5</option>
  10. </select>
  11. <input type="submit" name="submit" value="submit">
  12. </form>
  13. </body>
  14. </html>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

Re: php dropdown menu remembers selected option

 
0
  #4
Apr 29th, 2009
  1. <body>
  2. <?php
  3. include 'cms/core/config.php';
  4. include 'cms/core/opendb.php';
  5.  
  6. $query = "SELECT id, description, keywords, author, language, rating, classification, distribution, robots, revisit, copyright, email, updated ". "FROM meta ". "WHERE id = '7'";
  7. $result = mysql_query($query) or die('Error : ' . mysql_error());
  8. list($id, $description, $keywords, $author, $language, $rating, $classification, $distribution, $robots, $revisit, $copyright, $email, $updated) = mysql_fetch_array($result, MYSQL_NUM);
  9.  
  10.  
  11. include 'cms/core/closedb.php';
  12. ?>
  13. <form method="post" action="default.php?s=editmeta">
  14. <input type="hidden" name="id" value="5">
  15. <table width="700" border="0" cellpadding="5" cellspacing="0" class="box">
  16. <tr>
  17. <td width="100" valign="top">Description:</td>
  18. <td><input name="description" type="text" id="description" value="<?=$description;?>" size="100"></td>
  19. </tr>
  20. <tr>
  21. <td width="100" valign="top">Keywords:</td>
  22. <td><input name="keywords" type="text" id="keywords" value="<?=$keywords;?>" size="100"></td>
  23. </tr>
  24. <tr>
  25. <td width="100" valign="top">Author:</td>
  26. <td><input name="author" type="text" id="author" value="<?=$author;?>" size="100"></td>
  27. </tr>
  28. <tr>
  29. <td width="100" valign="top">Language:</td>
  30. <td>
  31. <select name='language' id="language" >
  32. <option value="en" <?php if($_REQUEST['$language']=="en") { echo "selected"; }?>>English</option>
  33. <option value="ko" <?php if($_REQUEST['$language']=="ko") { echo "selected"; }?>>Korean</option>
  34. <option value="it" <?php if($_REQUEST['$language']=="it") { echo "selected"; }?>>Italian</option>
  35. </select>
  36. </td>
  37. </tr>
  38. <tr>
  39. <td width="100" valign="top">Rating:</td>
  40. <td>
  41. <select name="rating" id="rating">
  42. <option value="general">general</option>
  43. <option value="mature">mature</option>
  44. <option value="restricted">restricted</option>
  45. </select>
  46. </td>
  47. </tr>
  48. <tr>
  49. <td width="100" valign="top">Classification:</td>
  50. <td><input name="classification" type="text" id="classification" value="<?=$classification;?>" size="100"></td>
  51. </tr>
  52. <tr>
  53. <td width="100" valign="top">Distribution:</td>
  54. <td>
  55. <select name="distribution" id="distribution">
  56. <option value="global">global</option>
  57. <option value="local">local</option>
  58. <option value="iu">internal use</option>
  59. </select>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td width="100" valign="top">Robots:</td>
  64. <td>
  65. <select name="robots" id="robots">
  66. <option value="index, follow">index, follow</option>
  67. <option value="noindex, nofollow">noindex, nofollow</option>
  68. </select>
  69. </td>
  70. </tr>
  71. <tr>
  72. <td width="100" valign="top">Revisit After:</td>
  73. <td>
  74. <select name="revisit" id="revisit">
  75. <option value="7 days">7 days</option>
  76. <option value="14 days">14 days</option>
  77. <option value="30 days">30 days</option>
  78. <option value="60 days">60 days</option>
  79. </select>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td width="100" valign="top">Copyright:</td>
  84. <td><input name="copyright" type="text" id="copyright" value="<?=$copyright;?>" size="100"></td>
  85. </tr>
  86. <tr>
  87. <td width="100" valign="top">Email:</td>
  88. <td><input name="email" type="text" id="email" value="<?=$email;?>" size="100"></td>
  89. </tr>
  90. <tr>
  91. <td colspan="2" align="center"><input name="update" type="submit" id="update" value="Update Content"></td>
  92. </tr>
  93. <tr>
  94. <td colspan="2"><p align="center"><a href="javascript:history.back();">cancel and go back</a></p></td>
  95. </tr>
  96. </table>
  97. </form>
  98. </body>
  99. </html>

the above the my code updated with your script, still nothing. maybe i integrated wronly ? i dont know ?! just yo let you know the language field name is "language" and in id row 7 corrently there is ko so it suppose to show korean selected but still nothing
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: php dropdown menu remembers selected option

 
0
  #5
Apr 29th, 2009
Its not $_REQUEST['$language'] , but, $_REQUEST['language'].
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

Re: php dropdown menu remembers selected option

 
0
  #6
Apr 29th, 2009
did it as you told me bro

you can have a look at it here

still nothing. full code as it is now:

  1. <body>
  2. <?php
  3. include 'cms/core/config.php';
  4. include 'cms/core/opendb.php';
  5.  
  6. $query = "SELECT id, description, keywords, author, language, rating, classification, distribution, robots, revisit, copyright, email, updated ". "FROM meta ". "WHERE id = '7'";
  7. $result = mysql_query($query) or die('Error : ' . mysql_error());
  8. list($id, $description, $keywords, $author, $language, $rating, $classification, $distribution, $robots, $revisit, $copyright, $email, $updated) = mysql_fetch_array($result, MYSQL_NUM);
  9.  
  10. ?>
  11. <form method="post" action="default.php?s=editmeta">
  12. <input type="hidden" name="id" value="5">
  13. <table width="700" border="0" cellpadding="5" cellspacing="0" class="box">
  14. <tr>
  15. <td width="100" valign="top">Description:</td>
  16. <td><input name="description" type="text" id="description" value="<?=$description;?>" size="100"></td>
  17. </tr>
  18. <tr>
  19. <td width="100" valign="top">Keywords:</td>
  20. <td><input name="keywords" type="text" id="keywords" value="<?=$keywords;?>" size="100"></td>
  21. </tr>
  22. <tr>
  23. <td width="100" valign="top">Author:</td>
  24. <td><input name="author" type="text" id="author" value="<?=$author;?>" size="100"></td>
  25. </tr>
  26. <tr>
  27. <td width="100" valign="top">Language:</td>
  28. <td>
  29. <select name='language' id="language" >
  30. <option value="en" <?php if($_REQUEST['language']=="en") { echo "selected"; }?>>English</option>
  31. <option value="ko" <?php if($_REQUEST['language']=="ko") { echo "selected"; }?>>Korean</option>
  32. <option value="it" <?php if($_REQUEST['language']=="it") { echo "selected"; }?>>Italian</option>
  33. </select>
  34. </td>
  35. </tr>
  36. <tr>
  37. <td width="100" valign="top">Rating:</td>
  38. <td>
  39. <select name="rating" id="rating">
  40. <option value="general">general</option>
  41. <option value="mature">mature</option>
  42. <option value="restricted">restricted</option>
  43. </select>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td width="100" valign="top">Classification:</td>
  48. <td><input name="classification" type="text" id="classification" value="<?=$classification;?>" size="100"></td>
  49. </tr>
  50. <tr>
  51. <td width="100" valign="top">Distribution:</td>
  52. <td>
  53. <select name="distribution" id="distribution">
  54. <option value="global">global</option>
  55. <option value="local">local</option>
  56. <option value="iu">internal use</option>
  57. </select>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td width="100" valign="top">Robots:</td>
  62. <td>
  63. <select name="robots" id="robots">
  64. <option value="index, follow">index, follow</option>
  65. <option value="noindex, nofollow">noindex, nofollow</option>
  66. </select>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td width="100" valign="top">Revisit After:</td>
  71. <td>
  72. <select name="revisit" id="revisit">
  73. <option value="7 days">7 days</option>
  74. <option value="14 days">14 days</option>
  75. <option value="30 days">30 days</option>
  76. <option value="60 days">60 days</option>
  77. </select>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td width="100" valign="top">Copyright:</td>
  82. <td><input name="copyright" type="text" id="copyright" value="<?=$copyright;?>" size="100"></td>
  83. </tr>
  84. <tr>
  85. <td width="100" valign="top">Email:</td>
  86. <td><input name="email" type="text" id="email" value="<?=$email;?>" size="100"></td>
  87. </tr>
  88. <tr>
  89. <td colspan="2" align="center"><input name="update" type="submit" id="update" value="Update Content"></td>
  90. </tr>
  91. <tr>
  92. <td colspan="2"><p align="center"><a href="javascript:history.back();">cancel and go back</a></p></td>
  93. </tr>
  94. </table>
  95. </form>
  96. <? include 'cms/core/closedb.php'; ?>
  97. </body>
  98. </html>

dont know why its not working it seems to be good
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,739
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 330
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: php dropdown menu remembers selected option

 
0
  #7
Apr 29th, 2009
I totally misunderstood your question. I thought you wanted to display selected dropdown list value after submitting the page. But anyway, try this one.
  1. <body>
  2. <?php
  3. include 'cms/core/config.php';
  4. include 'cms/core/opendb.php';
  5.  
  6. $query = "SELECT id, description, keywords, author, language, rating, classification, distribution, robots, revisit, copyright, email, updated FROM meta WHERE id = '7'";
  7. $result = mysql_query($query) or die('Error : ' . mysql_error());
  8. list($id, $description, $keywords, $author, $language, $rating, $classification, $distribution, $robots, $revisit, $copyright, $email, $updated) = mysql_fetch_array($result, MYSQL_NUM);
  9.  
  10. ?>
  11. <form method="post" action="default.php?s=editmeta">
  12. <input type="hidden" name="id" value="5">
  13. <table width="700" border="0" cellpadding="5" cellspacing="0" class="box">
  14. <tr>
  15. <td width="100" valign="top">Description:</td>
  16. <td><input name="description" type="text" id="description" value="<?=$description;?>" size="100"></td>
  17. </tr>
  18. <tr>
  19. <td width="100" valign="top">Keywords:</td>
  20. <td><input name="keywords" type="text" id="keywords" value="<?=$keywords;?>" size="100"></td>
  21. </tr>
  22. <tr>
  23. <td width="100" valign="top">Author:</td>
  24. <td><input name="author" type="text" id="author" value="<?=$author;?>" size="100"></td>
  25. </tr>
  26. <tr>
  27. <td width="100" valign="top">Language:</td>
  28. <td>
  29. <select name='language' id="language" >
  30. <option value="en" <?php if($language=="en") { echo "selected"; }?>>English</option>
  31. <option value="ko" <?php if($language=="ko") { echo "selected"; }?>>Korean</option>
  32. <option value="it" <?php if($language=="it") { echo "selected"; }?>>Italian</option>
  33. </select>
  34. </td>
  35. </tr>
  36. <tr>
  37. <td width="100" valign="top">Rating:</td>
  38. <td>
  39. <select name="rating" id="rating">
  40. <option value="general">general</option>
  41. <option value="mature">mature</option>
  42. <option value="restricted">restricted</option>
  43. </select>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td width="100" valign="top">Classification:</td>
  48. <td><input name="classification" type="text" id="classification" value="<?=$classification;?>" size="100"></td>
  49. </tr>
  50. <tr>
  51. <td width="100" valign="top">Distribution:</td>
  52. <td>
  53. <select name="distribution" id="distribution">
  54. <option value="global">global</option>
  55. <option value="local">local</option>
  56. <option value="iu">internal use</option>
  57. </select>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td width="100" valign="top">Robots:</td>
  62. <td>
  63. <select name="robots" id="robots">
  64. <option value="index, follow">index, follow</option>
  65. <option value="noindex, nofollow">noindex, nofollow</option>
  66. </select>
  67. </td>
  68. </tr>
  69. <tr>
  70. <td width="100" valign="top">Revisit After:</td>
  71. <td>
  72. <select name="revisit" id="revisit">
  73. <option value="7 days">7 days</option>
  74. <option value="14 days">14 days</option>
  75. <option value="30 days">30 days</option>
  76. <option value="60 days">60 days</option>
  77. </select>
  78. </td>
  79. </tr>
  80. <tr>
  81. <td width="100" valign="top">Copyright:</td>
  82. <td><input name="copyright" type="text" id="copyright" value="<?=$copyright;?>" size="100"></td>
  83. </tr>
  84. <tr>
  85. <td width="100" valign="top">Email:</td>
  86. <td><input name="email" type="text" id="email" value="<?=$email;?>" size="100"></td>
  87. </tr>
  88. <tr>
  89. <td colspan="2" align="center"><input name="update" type="submit" id="update" value="Update Content"></td>
  90. </tr>
  91. <tr>
  92. <td colspan="2"><p align="center"><a href="javascript<b></b>:history.back();">cancel and go back</a></p></td>
  93. </tr>
  94. </table>
  95. </form>
  96. <? include 'cms/core/closedb.php'; ?>
  97. </body>
  98. </html>
Oh btw, Don't use <? [short tags]. Its disabled on most of the servers by default.
Last edited by nav33n; Apr 29th, 2009 at 3:54 pm.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

Re: php dropdown menu remembers selected option

 
0
  #8
Apr 29th, 2009
no worries man, made changes works like good thanks alot for your help bro
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 1
Reputation: ryanlowe is an unknown quantity at this point 
Solved Threads: 0
ryanlowe ryanlowe is offline Offline
Newbie Poster

test

 
0
  #9
May 2nd, 2009
  1.  
  2. print_r(array(0,1,2));
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 19
Reputation: odysea is an unknown quantity at this point 
Solved Threads: 0
odysea odysea is offline Offline
Newbie Poster

Re: test

 
0
  #10
May 3rd, 2009
what does that mean ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC