我想製作一個腳本,將PM發送給從MySQL中選擇的用戶。如何使用AJAX,PHP和MySQL發送個人消息?
我有用戶列表:
http://i.stack.imgur.com/9fRZV.png
當我點擊PM按鈕,我得到javascipt的sceen:
http://i.stack.imgur.com/4bJ9A.png
如何填寫的Javascript屏幕領域與用戶價值自動列出並將值發送到其他PHP文件(使用AJAX)?
用戶名單表的代碼:
所有的 <!-- Table -->
<table class="table table-condensed">
<tr class="bg_h">
<th>Username</th>
<th>Email</th>
<th>Rank</th>
<th>Active?</th>
<th>Registration date</th>
<th>IP</th>
<th>PM</th>
</tr>
<?php
$sql = "SELECT * FROM users ORDER BY user_id ASC";
$query = $dbh->prepare($sql);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $row) {
?>
<tr class="">
<td><?php echo $row['user_name']; ?></td>
<td><?php echo $row['user_email']; ?></td>
<td>
<?php
PHP code of getting user rank.
?>
</td>
<td>
<?php
PHP code to chech is user active.
?>
</td>
<td>
<?php echo $row['user_registration_datetime']; ?>
</td>
<td>
<?php echo $row['user_registration_ip']; ?>
</td>
<td>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#send-pm">@PM</button>
<div class="modal fade" id="send-pm" tabindex="-1" role="dialog" aria-labelledby="send-pm-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="send-pm-label">Send personal message</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="name" class="control-label">Receiver name</label>
<textarea style="height:35px;" name="name" id="name" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="email" class="control-label">Email</label>
<textarea style="height:35px;" name="email" id="email" class="form-control" ></textarea>
</div>
<div class="form-group">
<label for="message" class="control-label">Message</label>
<textarea style="height:250px;" name="message" id="message" class="form-control" ></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" id="submit" class="btn btn-primary">SEND</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php
}
?>
</table>
您是否正在使用當前文件發生錯誤?我建議清理你的問題,只提供必要的代碼,因爲我無法弄清楚你可能會遇到什麼問題。 – arleslie 2015-02-23 17:49:06
我不知道如何用Mysql值填寫AJAX textareas。 因爲我通過foreach獲得所有用戶。 foreach($ list as $ row){ echo $ row ['user_name']; } – senti3rd 2015-02-23 17:53:21
我認爲這個問題缺少必要的代碼,它是處理PM按鈕單擊事件的JavaScript,並打開模式對話框來發送消息。在這一點上,你需要從表格行中提取用戶名和電子郵件,並填充相關的字段。 – GarethD 2015-02-23 17:57:14