Javascript 如何将变量传递给引导模式
我想获得有关将变量传递给引导模式的帮助。在此之前,我已经编写了代码,但我正在为用户拥有的每个“对话”创建一个新的模式(根据用户的用户名为模式生成唯一的名称,因此每个模式都有一个唯一的名称,可以调用) 我认为只需将一些变量传递给modal,并生成SQL来从DB中提取这些变量的“消息”,这可能是一种更好的编码实践和总体设计,所以我正在尝试让它工作 我遇到了一个问题:1)还没有完全理解jquery;2)如何将变量从jquery传递到php。我知道我需要一个带有一些JS/Jquery内容的脚本标记。。到目前为止,我有以下几点。。(感谢所有帮助!)Javascript 如何将变量传递给引导模式,javascript,php,jquery,sql,modal-dialog,Javascript,Php,Jquery,Sql,Modal Dialog,我想获得有关将变量传递给引导模式的帮助。在此之前,我已经编写了代码,但我正在为用户拥有的每个“对话”创建一个新的模式(根据用户的用户名为模式生成唯一的名称,因此每个模式都有一个唯一的名称,可以调用) 我认为只需将一些变量传递给modal,并生成SQL来从DB中提取这些变量的“消息”,这可能是一种更好的编码实践和总体设计,所以我正在尝试让它工作 我遇到了一个问题:1)还没有完全理解jquery;2)如何将变量从jquery传递到php。我知道我需要一个带有一些JS/Jquery内容的脚本标记。。到
可能重复的
<?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>";