Hi guys,, need some help pls.. i have a PHP code here that lets a user send a message to multiple recipients using the "phonebook" (from database) as the main list. I used an array to temporarily hold all the desired recipients for the current user. So I have a two box, with each for displaying. The user will clicks the name from the phonebook lisy and clicks "Add" button to add on the temporary list on the other select box. The problem is, whenever I use the "onChange" function in javascript; the array accepts only one recipients, and when I try to add, it replaces the first one. :(
Here is my code:
$recipients = array();
<script type="text/javascript">
// How do I place the array here? <br>
function reload_page(){<br>
i=document.maillinglist.firstletter.selectedIndex;<br>
this.location='./group_msg.php?firstletter='+document.maillinglist.firstletter.options[i].value;<br>
} <br>
function add(){
<?
$user = $_POST['non_members'];
foreach ($user as $user){
$recipients[] = $user;
}
?>
}
$conn = pg_connect("host=localhost user=sa dbname=messaging");
if(isset($_GET['firstletter'])){
$letter=$_GET['firstletter'];
} else {
$letter='a';}
print "</HEAD><center>";
print "<h3><center><b><u>GROUP MESSAGE</u></b></center></h3>";
print "<table width=420 border="1" align="center" bgcolor=lightblue>";
print "<form name=maillinglist method=POST><tr>";
print "<td width=210>";
print "<select style='width:210px' name="firstletter" onChange="reload_page()">";
for($chr_loop=97;$chr_loop<=122;$chr_loop++){
$alphabet = chr($chr_loop);
# Displays list of users arranged by letters - this works fine
if($alphabet==$letter){
print "\t\t<option value='$alphabet' selected>-------------------- $alphabet --------------------</option>\n";
} else {
print "\t\t<option value='$alphabet'>-------------------- $alphabet --------------------</option>\n";}
}
print "</select><td></td><td></td></tr></select>";
print "<td><select style='width:210px' name=\"non_members[]\" size=10 width=200>";
$sql = "select name from test_phonebook where name like '$letter%';";
$result = pg_query($conn, $sql);
# Display users from phonebook using the letter chosen
while($row = pg_fetch_assoc($result)){
$my_name = $row['name'];
print "<option width=200 value=\"$my_name\">$my_name</option>";
}
print "</td>";
print "</select>";
print "<td><input type=submit name=add value=\"->>\" onClick=\"add()\"><br><input type=submit name=del value=\"<<-\"></td>";
print "<td><select name=\"members[]\" style='width:210px' size=10>";
# Display temporary recipients - problem: ONLY DISPLAYS ONE VALUE
while (list ($key, $val) = each ($recipients)) {
echo "$key -> $val <br>";
print "<option width=200 value=\"$val\">$val</option>";
}
print "</select></table></form>";
My aim here, is to place all recipients that the user desires to an array, without losing the previous value added.