Hello,
There are many things you can do like move the form, textarea outside of the while loop. Add ability to select users to whom message will be sent etc, I have modified the code which will allow you send message to selected users only. I have not changed the way data gets sent to the send_message.php. However by adding a checkbox your send_message.php will be able to find out the users to whom message needs to send. The post data should look something like shown below.
chk_0=chk_0&user_0=john435&user_1=admin&chk_2=chk_2&user_2=operator
The modified code is shown below.
<html>>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="gcm_style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
});
function sendPushNotification(id) {
var data = $('#frmMain').serialize();
$.ajax({
url: "send_message.php",
type: 'GET',
data: data,
beforeSend: function() {
},
success: function(data, textStatus, xhr) {
$('#taMesage').val("");
},
error: function(xhr, textStatus, errorThrown) {
}
});
return false;
}
</script>
</head>
<body>
<?
include_once 'db_functions.php';
$db = new DB_Functions();
$users = $db->getAllUsers();
if ($users != false)
$no_of_users = mysql_num_rows($users);
else
$no_of_users = 0;
if ($no_of_users > 0) {
$cntr = 0;
?>
<form id="frmMain" name="frmMain" method="post" onsubmit="return sendPushNotification()">
<?
while ($row = mysql_fetch_array($users)) {
$userId = $row[0];
$chkId = "chk_" . $cntr;
$userFldId = "user_" . $cntr;
?>
<div>
<label>Name: </label><span class="textbox"><?=$row[1]?></span><br/>
<label>Send Email :</label><input type="checkbox" id="<?=$chkId?>" value="<?=$chkId?>"/>
<input type="hidden" name="<?=$userFldId?>" value="<?=$userId?>"/>
</div>
<?
$cntr = $cntr + 1;
}?>
<div>
<label>Email:</label>
<textarea rows="3" name="message" cols="25" class="txt_message" id="taMesage"></textarea>
</div>
<input type="submit" class="send_btn" value="Send"/>
</form>
<?
} else { ?>
No Users Registered Yet!
</body>
</html>
Regards,