| | |
Drop-down Menu with values based on Table data
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 42
Reputation:
Solved Threads: 0
Hi,
I am trying to compile a detail page. Here is the code below:
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 ;-)
I am trying to compile a detail page. Here is the code below:
PHP Syntax (Toggle Plain Text)
<?php require_once('auth.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Village Of Hope Worship</title> <style type="text/css"> <!-- .style13 { font-size: 12px; color: #70283C; font-weight: bold; } .style14 { font-size: 12px; font-weight: bold; } .style15 { color: #000000; font-weight: bold; } .style17 { font-size: 12px; color: #884D5E; } .style18 { font-size: 12px; color: #000000; font-weight: bold; } --> </style> </head> <body> <?php virtual('/VOH/INC/logo.php'); ?> <br /> <table width="700" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#E7EEF6"> <tr> <td><div align="center" style="color: #70283C"><strong>Service Date Detail </strong></div></td> </tr> </table> <br /> <table width="700" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td width="593" bgcolor="#FFFFFF"><div align="center" style="color: #000000"> <div align="left"><strong><a href="/VOH/service_edit_list.php">Return to Date List</a> </strong></div> </div></td> <td width="93" bgcolor="#FFFFFF"><div align="right"><span class="style18"><a href="#">Delete this date </a></span></div></td> </tr> </table> <table width="700" border="0" align="center" cellpadding="2" cellspacing="2" bgcolor="#E7EEF6"> <tr> <td width="343" bgcolor="#FFFFFF"><div align="center" style="color: #70283C; font-size: 12px"> <div align="center"> <p>Select a Volunteer and choose<br /> ADD to make them available on this date:</p> Volunteers <select name="SelVol" id="SelVol"> </select> <span class="style15"><a href="#">ADD</a></span> <span class="style15"><a href="#">Email</a></span> <p> </p> </div> </div></td> <td width="343" bgcolor="#FFFFFF"><div align="center"><span class="style13">ASSIGNED VOLUNTEERS </span></div></td> </tr> <tr align="center" valign="top" bordercolor="#999999"> <td height="226" bgcolor="#FFFFFF"> <span class="style17">Volunteers who are AVAILABLE on this date: </span> <table width="336" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="124" bgcolor="#E7EEF6"><span class="style14">Name</span></td> <td width="33" bgcolor="#E7EEF6"><div align="center" class="style14">Note</div></td> <td width="36" bgcolor="#E7EEF6"><div align="center" class="style14">Email</div></td> <td width="69" bgcolor="#E7EEF6"><div align="center" class="style14">Unavailable</div></td> <td width="42" bgcolor="#E7EEF6"><div align="center"><span class="style14">Assign</span></div></td> </tr> </table></td> <td bgcolor="#FFFFFF"><span class="style17">Volunteers who have been ASSIGNED to this date: </span><br /> <table width="336" border="0" cellspacing="2" cellpadding="2"> <tr> <td width="124" bgcolor="#E7EEF6"><span class="style14">Name</span></td> <td width="33" bgcolor="#E7EEF6"><div align="center" class="style14">Note</div></td> <td width="36" bgcolor="#E7EEF6"><div align="center" class="style14">Email</div></td> <td width="69" bgcolor="#E7EEF6"><div align="center" class="style14">Unavailable</div></td> <td width="42" bgcolor="#E7EEF6"><div align="center"><span class="style14">Assign</span></div></td> </tr> </table></td> </tr> </table> <br><br> </body> </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 ;-)
•
•
Join Date: Mar 2008
Posts: 153
Reputation:
Solved Threads: 20
You could hard code them like this
hard code it like this
or use a database like this:
php Syntax (Toggle Plain Text)
<select name="SelVol" id="SelVol"> <option value = "1">Joe Friendly</option> <option value = "2">Mary Jackson</option> </select>
hard code it like this
php Syntax (Toggle Plain Text)
<select name="SelVol" id="SelVol"> <?php $people = array(1=>"Joe Friendly", 2=>"Mary Jackson", 3=>"Harold Balzonia" ); foreach ($people as $key=>$person) { echo "<option value = \"".$key."\">".$person."</option>\n"; } ?>
or use a database like this:
php Syntax (Toggle Plain Text)
<select name="SelVol" id="SelVol"> <?php $conn = mysql_connect("localhost","user","pass"); mysql_select_db("yourdb",$conn); $query = "select id,firstname,lastname from mytable order by lastname,firstname"; $result = mysql_query ($query) or die ("select failed : ".mysql_error()); while($line = mysql_fetch_array($result)) { echo "<option value = \"".$line[0]."\">".$line[2].",".$line[1]."</option>\n"; } ?> </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".
•
•
Join Date: Jul 2009
Posts: 42
Reputation:
Solved Threads: 0
•
•
•
•
You could hard code them like this
php Syntax (Toggle Plain Text)
<select name="SelVol" id="SelVol"> <?php $conn = mysql_connect("localhost","user","pass"); mysql_select_db("yourdb",$conn); $query = "select id,firstname,lastname from mytable order by lastname,firstname"; $result = mysql_query ($query) or die ("select failed : ".mysql_error()); while($line = mysql_fetch_array($result)) { echo "<option value = \"".$line[0]."\">".$line[2].",".$line[1]."</option>\n"; } ?> </select>
![]() |
Similar Threads
- Limit Drop Down Menu Options Based on Option Selected in Other Dropdown (PHP)
- Calling JS From Drop Down Menu (JavaScript / DHTML / AJAX)
- using drop down menu with to insert data through php (PHP)
- Linking a Drop down menu option to a Mysql table. (MySQL)
- help with menu selection based from other menu showing "selected" entry from db (PHP)
- displaying data from oracle database in drop down menu using jsp (JSP)
- dynamic drop down menu in php (PHP)
- opopulate textfields based on drop down menu selection (ColdFusion)
Other Threads in the PHP Forum
- Previous Thread: Displaying LINKS based on a SESSION Variable
- Next Thread: mysql_fetch_array(): Help with error needed
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend






