I am retrieving a list from my sql db into a select option box which works fine. The other part of the script should enable a selected name to be printed into a textarea, however this bit is giving a headache. Hope someone could be of help.
<HTML>
<HEAD>
<TITLE>List of Employees</TITLE>
<h1><center><img src="images/slim.gif" width="543" height="72"></p></h1>
</HEAD>
<BODY>
<?php
session_start();
//connect to database
$conn = mysql_connect("localhost", "", "")
or die(mysql_error());
mysql_select_db("me",$conn) or die(mysql_error());
if ($_POST[op] != "view") {
//haven't seen the form, so show it
//get parts of records
$get_list = "select emp_no, concat_ws(', ', lname, fname) as display_name
from employee order by lname, fname";
$get_list_res = mysql_query($get_list) or die(mysql_error());
if (mysql_num_rows($get_list_res) < 1) {
//no records
echo "<p><em>Sorry, no records to select!</em></p>";
} else {
//has records, so get results and print in a form
echo "
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<P><strong>List of Employees:</strong><br>
<select name=\"sel_id\">
<option value=\"\">— Select Colleagues —</option>";
while ($recs = mysql_fetch_array($get_list_res)) {
$emp_no = $recs['emp_no'];
$display_name = stripslashes($recs['display_name']);
echo "<option value=\"$emp_no\">
$display_name</option>";
}
echo "
</select>
<input type=\"hidden\" name=\"op\" value=\"view\">
<p><input type=\"submit\" name=\"submit\"
value=\"Add to List\"></p>
</FORM>";
}
} else if ($_POST[op] == "view") {
$get_addresses = "select emp_no, fname, lname, dept, position
from employee where emp_no = $_POST[sel_id]";
$get_addresses_res = mysql_query($get_addresses);
if (mysql_num_rows($get_addresses_res) > 0) {
// don't have anything doing
while ($add_info = mysql_fetch_array($get_addresses_res)) {
$my_id = $add_info[emp_no];
$my_fname = $add_info[fname];
$my_lname = $add_info[lname];
$my_dept = $add_info[dept];
$my_position = $add_info[position];
$emp_list = "$my_id $my_fname $my_lname";
// echo "$emp_list $my_fname $my_lname";
$emp_array = array ($emp_list);
$emp_id = array ($my_id);
// print the emp_array into the text area
for($x=0; $x<=count($emp_array); $x++)
{
echo "textspace";
}
}
}
}
?>
<textarea id="employees" name="textspace" cols="50" rows="5"></textarea>
</BODY>
</HTML>