我想获得将变量传递给bootstrap模式的帮助。我之前有代码工作,但我正在为用户拥有的每个“对话”创建一个新模式(根据用户的用户名生成一些用于模态的唯一名称,因此每个模态都有一个唯一的名称并且可以被称为)。
我认为只是将一些变量传递给模态并生成SQL以从数据库中提取这些变量的“消息”可能是一个更好的编码实践和整体设计,所以我试图让这个工作。
我遇到了一个问题,1)完全不了解jquery和2)如何将变量从jquery传递给php。我知道我需要一个带有一些JS / Jquery东西的SCRIPT标签..到目前为止,我有以下内容..(所有帮助表示赞赏!)
<?php
//Message Center
//Query to look for unique users who have sent a message to the user, ordered by last person to send a message
$sql = "SELECT m.mFrom, MAX(m.date) as date, m.mTo, u.first, u.username, u.id
FROM messages m
INNER JOIN users u ON u.id = m.mFrom
WHERE mTo = '".$userId."'
GROUP BY mFrom
ORDER BY date DESC";
$result = mysqli_query($db,$sql);
echo "<h3 class=\"text-center\">Message Center</h3>";
echo "<table class=\"table table-hover\"><tr><th>From</th><th>Last Message Received</th><th>Unread?</th><th>Conversation</th></tr>";
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo "<tr><td>".$row["first"]."</td><td>".$row["date"]."</td><td>glyphicon here</td>
<td>
<button type='button' class='btn btn-primary btn-md' data-toggle='modal' data-id='".$row["id"]."' href='#messagesModal'>See Conversation</button>
</td></tr>";
}
echo "
<div class='modal fade' id='messagesModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>
<div class='modal-dialog' role='document'>
<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='myModalLabel'>Conversation with ".$row["first"]."</h4>
</div>
<div class='modal-body'>";
//Query to pull all the messages between the user and other user
$sql2 = "SELECT id, mFrom, message, date
FROM messages
WHERE (mFrom = '".$row["mFrom"]."' AND mTo = '".$userId."')
OR (mFrom = '".$userId."' AND mTo = '".$row["mFrom"]."')
LIMIT 50";
$result2 = mysqli_query($db, $sql2);
while($row2 = $result2->fetch_assoc()){
if ($userId == $row2["mFrom"]){
echo "<div class=\"text-right\"><div class='alert alert-success' role='alert'><small>".$row2["date"]."</small><br>".$row2["message"]."</div></div><br>";
}
else{
echo "<div class=\"text-left\"><div class='alert alert-warning' role='alert'><small>".$row2["date"]."</small><br>".$row2["message"]."</div></div><br>";
}
}
echo "</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>
</div>";
}
echo "</table>";
&GT;