Hi people.
Could anyone help me here, i need to output two fields from my sql database, and join them together so that the dropdown list in my CMS page displays the first and last name of a member of staff.
the table name is called tbl_staff
the firstname field is called staff_nameFirst
the surname field is called staff_nameLast
All help will be appreciated.
Many thanks,
Nick.
Display database info in dropdown list
Moderator: General Moderators
-
jamiel
- Forum Contributor
- Posts: 276
- Joined: Wed Feb 22, 2006 5:17 am
- Location: London, United Kingdom
Code: Select all
SELECT CONCAT(staff_nameFirst , ' ', staff_nameLast) FROM tbl_staffCode: Select all
function dropdown($options_array, $selected = null)
{
$return = null;
foreach($options_array as $option)
{
$return .= '<option value="'.$option.'"'.
(($option == $selected) ? ' selected="selected"' : null ).
'>'.ucwords($option).'</option>'."\n";
}
return $return;
}
// DB connect stuff here
$query = "SELECT `staff_nameFirst`, `staff_nameLast` FROM `tbl_staff` ORDER BY `staff_nameLast` ASC";
$result = mysql_query($query) or die($query ."<br>\n". mysql_error());
$names = array();
while($row = mysql_fetch_assoc($result))
{
$names[] = $row['staff_nameFirst'] .' '. $row['staff_nameLast'];
}
echo '<p><label>Name</label> <select name="name" size="1">'.dropdown($names).'</select></p>'."\n";