Drop-down Menu with values based on Table data

Thread Solved

Join Date: Jul 2009
Posts: 42
Reputation: dwdata is an unknown quantity at this point 
Solved Threads: 0
dwdata dwdata is offline Offline
Light Poster

Drop-down Menu with values based on Table data

 
0
  #1
Jul 5th, 2009
Hi,

I am trying to compile a detail page. Here is the code below:

  1. <?php
  2. require_once('auth.php');
  3. ?>
  4.  
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  10. <title>Village Of Hope Worship</title>
  11. <style type="text/css">
  12. <!--
  13. .style13 {
  14. font-size: 12px;
  15. color: #70283C;
  16. font-weight: bold;
  17. }
  18. .style14 {
  19. font-size: 12px;
  20. font-weight: bold;
  21. }
  22. .style15 {
  23. color: #000000;
  24. font-weight: bold;
  25. }
  26. .style17 {
  27. font-size: 12px;
  28. color: #884D5E;
  29. }
  30. .style18 {
  31. font-size: 12px;
  32. color: #000000;
  33. font-weight: bold;
  34. }
  35. -->
  36. </style>
  37. </head>
  38.  
  39. <body>
  40.  
  41. <?php virtual('/VOH/INC/logo.php'); ?>
  42. <br />
  43. <table width="700" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#E7EEF6">
  44. <tr>
  45. <td><div align="center" style="color: #70283C"><strong>Service Date Detail </strong></div></td>
  46. </tr>
  47. </table>
  48. <br />
  49.  
  50. <table width="700" border="0" align="center" cellpadding="2" cellspacing="2">
  51. <tr>
  52. <td width="593" bgcolor="#FFFFFF"><div align="center" style="color: #000000">
  53. <div align="left"><strong><a href="/VOH/service_edit_list.php">Return to Date List</a> </strong></div>
  54. </div></td>
  55. <td width="93" bgcolor="#FFFFFF"><div align="right"><span class="style18"><a href="#">Delete this date </a></span></div></td>
  56. </tr>
  57. </table>
  58. <table width="700" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#E7EEF6">
  59. <tr>
  60. <td width="343" bgcolor="#FFFFFF"><div align="center" style="color: #70283C; font-size: 12px">
  61. <div align="center">
  62. <p>Select a Volunteer and choose<br />
  63. ADD to make them available on this date:</p>
  64. Volunteers
  65.  
  66.  
  67. <select name="SelVol" id="SelVol">
  68. </select>
  69.  
  70. &nbsp;<span class="style15"><a href="#">ADD</a></span>
  71. &nbsp;<span class="style15"><a href="#">Email</a></span>
  72. <p>
  73. </p>
  74. </div>
  75. </div></td>
  76. <td width="343" bgcolor="#FFFFFF"><div align="center"><span class="style13">ASSIGNED VOLUNTEERS </span></div></td>
  77. </tr>
  78. <tr align="center" valign="top" bordercolor="#999999">
  79. <td height="226" bgcolor="#FFFFFF">
  80. <span class="style17">Volunteers who are AVAILABLE on this date: </span>
  81. <table width="336" border="0" cellspacing="2" cellpadding="2">
  82. <tr>
  83. <td width="124" bgcolor="#E7EEF6"><span class="style14">Name</span></td>
  84. <td width="33" bgcolor="#E7EEF6"><div align="center" class="style14">Note</div></td>
  85. <td width="36" bgcolor="#E7EEF6"><div align="center" class="style14">Email</div></td>
  86. <td width="69" bgcolor="#E7EEF6"><div align="center" class="style14">Unavailable</div></td>
  87. <td width="42" bgcolor="#E7EEF6"><div align="center"><span class="style14">Assign</span></div></td>
  88. </tr>
  89. </table></td>
  90. <td bgcolor="#FFFFFF"><span class="style17">Volunteers who have been ASSIGNED to this date: </span><br />
  91. <table width="336" border="0" cellspacing="2" cellpadding="2">
  92. <tr>
  93. <td width="124" bgcolor="#E7EEF6"><span class="style14">Name</span></td>
  94. <td width="33" bgcolor="#E7EEF6"><div align="center" class="style14">Note</div></td>
  95. <td width="36" bgcolor="#E7EEF6"><div align="center" class="style14">Email</div></td>
  96. <td width="69" bgcolor="#E7EEF6"><div align="center" class="style14">Unavailable</div></td>
  97. <td width="42" bgcolor="#E7EEF6"><div align="center"><span class="style14">Assign</span></div></td>
  98. </tr>
  99. </table></td>
  100. </tr>
  101. </table>
  102. <br><br>
  103.  
  104.  
  105.  
  106. </body>
  107. </html>

I want to display a list of ALL Volunteers (sorted by Last_Name then First_Name (asc)) in the list menu entry field "SelVol". I want to capture the value "id" but display in the drop-down list a concatenation of: Last_Name, a comma, a space, and First_Name. The TABLE name is "Volunteers".

There was a couple examples I searched the archives but I tried to insert them and kept getting errors. Please let me know how I need my code modified to get this to work.

Thanks ;-)
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 153
Reputation: kireol is an unknown quantity at this point 
Solved Threads: 20
kireol kireol is online now Online
Junior Poster

Re: Drop-down Menu with values based on Table data

 
0
  #2
Jul 5th, 2009
You could hard code them like this

  1. <select name="SelVol" id="SelVol">
  2. <option value = "1">Joe Friendly</option>
  3. <option value = "2">Mary Jackson</option>
  4. </select>

hard code it like this

  1. <select name="SelVol" id="SelVol">
  2. <?php
  3. $people = array(1=>"Joe Friendly",
  4. 2=>"Mary Jackson",
  5. 3=>"Harold Balzonia"
  6. );
  7. foreach ($people as $key=>$person)
  8. {
  9. echo "<option value = \"".$key."\">".$person."</option>\n";
  10. }
  11. ?>

or use a database like this:

  1. <select name="SelVol" id="SelVol">
  2. <?php
  3. $conn = mysql_connect("localhost","user","pass");
  4. mysql_select_db("yourdb",$conn);
  5. $query = "select id,firstname,lastname from mytable order by lastname,firstname";
  6. $result = mysql_query ($query) or die ("select failed : ".mysql_error());
  7. while($line = mysql_fetch_array($result))
  8. {
  9. echo "<option value = \"".$line[0]."\">".$line[2].",".$line[1]."</option>\n";
  10. }
  11. ?>
  12. </select>
Last edited by kireol; Jul 5th, 2009 at 9:09 pm.
Why do Daniweb moderators edit CODE tags into CODE=style but don't check "solved".
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 42
Reputation: dwdata is an unknown quantity at this point 
Solved Threads: 0
dwdata dwdata is offline Offline
Light Poster

Re: Drop-down Menu with values based on Table data

 
0
  #3
Jul 5th, 2009
Originally Posted by kireol View Post
You could hard code them like this

  1. <select name="SelVol" id="SelVol">
  2. <?php
  3. $conn = mysql_connect("localhost","user","pass");
  4. mysql_select_db("yourdb",$conn);
  5. $query = "select id,firstname,lastname from mytable order by lastname,firstname";
  6. $result = mysql_query ($query) or die ("select failed : ".mysql_error());
  7. while($line = mysql_fetch_array($result))
  8. {
  9. echo "<option value = \"".$line[0]."\">".$line[2].",".$line[1]."</option>\n";
  10. }
  11. ?>
  12. </select>
This worked perfectly. I added a SPACE after the COMMA to get it exactly the way I needed it. Every answer I get - the more I understand and learn ;-) Thanks much!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 153
Reputation: kireol is an unknown quantity at this point 
Solved Threads: 20
kireol kireol is online now Online
Junior Poster

Re: Drop-down Menu with values based on Table data

 
0
  #4
Jul 5th, 2009
no prob. programming isnt hard, it just takes time to learn it all.

please make sure you click solved
Why do Daniweb moderators edit CODE tags into CODE=style but don't check "solved".
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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