我有一个php循环,它从mysql表中收集所有数据并将其显示在html表中。在该表中,每一行都有一个详细信息按钮'
当用户点击详情按钮时,会出现一个模态。
这是我的代码
<table id="open" class="table table-bordered table-striped">
<thead>
<tr>
<th style="text-align: center;">Job Title</th>
<th style="text-align: center;">Assigned To</th>
<th style="text-align: center;">Name Or Class</th>
<th style="text-align: center;">Priority</th>
<th style="text-align: center;">Date</th>
<th style="text-align: center;">Added By</th>
<th style="text-align: center;">Days Open</th>
<th style="text-align: center;">Replies</th>
<th style="text-align: center;">Actions</th>
</tr>
</thead>
<tbody>
<?php
$getopenjobs = mysql_query("SELECT support.id, support.title, support.description, departments.name, support.assigned_to, support.name_class, support.priority, support.datetime, users.firstname, users.lastname, support.status, COUNT(support_replies.job_id) AS replies, DATEDIFF(CURDATE(), support.datetime) as 'difference', support_replies.reply
FROM support JOIN departments ON support.assigned_to = departments.id JOIN users ON support.added_by = users.id LEFT JOIN support_replies ON support.id = support_replies.job_id WHERE support.status ='1' GROUP BY id");
$count = 0;
echo '<tr>';
if (mysql_num_rows($getopenjobs) == 0) {
echo '<td colspan="9">No Open Jobs Found</td>';
} else {
while ($row = mysql_fetch_array($getopenjobs))
{
echo '<td style="';
if($row['assigned_to'] == '1') {
echo 'background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo 'background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo 'background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo 'background: #F56954; ';
}
echo 'text-align: left;">' . $row['title'] . '</td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo 'background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo 'background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo 'background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo 'background: #F56954; ';
}
echo 'text-align: center;">' . $row['name'] . '</td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo 'background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo 'background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo 'background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo 'background: #F56954; ';
}
echo 'text-align: center;">' . $row['name_class'] . '</td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo 'background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo 'background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo 'background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo 'background: #F56954; ';
}
echo 'text-align: center;">';
if($row['priority'] == '1') {
echo 'Low';
}
if($row['priority'] == '2') {
echo 'Medium';
}
if($row['priority'] == '3') {
echo '
High';
}
if($row['priority'] == '4') {
echo '
Very High';
}
if($row['priority'] == '5') {
echo '
Critical';
}
echo '<td style="';
if($row['assigned_to'] == '1') {
echo '
background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo '
background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo '
background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo '
background: #F56954; ';
}
echo 'text-align: center;">' . $row['datetime'] . '</td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo '
background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo '
background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo '
background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo '
background: #F56954; ';
}
echo 'text-align: center;">' . $row['firstname'] . ' ' . $row['lastname'] . '</td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo '
background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo '
background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo '
background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo '
background: #F56954; ';
}
echo 'text-align: center;"><span style="color: black;" class="step">' . $row['difference'] . '</span></td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo '
background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo '
background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo '
background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo '
background: #F56954; ';
}
echo 'text-align: center;"><span style="color: black;" class="step">' . $row['replies'] . '</span></td>';
echo '<td style="';
if($row['assigned_to'] == '1') {
echo '
background: #00C0EF; ';
}
if($row['assigned_to'] == '2') {
echo '
background: #F39C12; ';
}
if($row['assigned_to'] == '3') {
echo '
background: #00A65A; ';
}
if($row['assigned_to'] == '4') {
echo '
background: #F56954; ';
}
echo 'text-align: center;"><a data-datetime="' .
$row['datetime'] . '" data-recipientname="' .
$row['firstname'] . ' ' . $row['lastname'] . '"
data-id="' . $row['id'] . '" data-title="' .
$row['title'] . '" data-desc="' . $row['description'] .
'" data-toggle="modal" data-target="#details"
class="open-details btn btn-primary btn-sm">Details</a> </td>';
echo '</tr>';
$count++;
}
echo '<div class="modal fade" id="details" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<!-- Chat box -->
<div class="box-body chat" id="chat-box">
<!--JOB -->
<div style="position: left; width: 80%; background: #F2DEDE; border: 1px solid #A94442; border-radius: 8px; padding-left: 10px; padding-right: 10px; padding-top: 10px;" class="item">
<img src="img/avatar-placeholder.png" alt="user image"/>
<p class="message">
<a href="#" class="name">
<small class="time text-muted pull-right"><i class="fa fa-clock-o"></i></small>
<p class="recipientname"></p>
</a>
<p class="title"></p></br>
<p class="description"></p>
</p>
</div><!-- /.JOB -->';
$query = ("SELECT support_replies.reply, support_replies.datetime,
users.firstname, users.lastname
FROM support_replies
JOIN users on support_replies.added_by = users.id
WHERE support_replies.job_id = '" . $row['id'] . "'
ORDER BY support_replies.id DESC");
$row = mysql_query($query);
while( false !== ($replies = mysql_fetch_assoc($row)))
{
echo '<ul style="list-style:none; margin-left: 0; padding-left: 0;">';
echo '<li>';
echo '<div style="width: 80%; background: #DFF0D8; border: 1px solid #46763D; border-radius: 8px; padding-left: 10px; padding-right: 10px; padding-top: 10px; margin-left: 20%;" class="item">
<img src="img/avatar-placeholder.png" alt="user image"/>
<p class="message">
<a href="#" class="name">
<small class="text-muted pull-right"><i class="fa fa-clock-o"></i> ' . $replies['datetime'] . '</small>
' . $replies['firstname'] . ' ' . $replies['lastname'] . '
</a>
' . $replies['reply'] . '
</p>
</div><!-- /.item -->';
echo '</li>';
echo '</ul>';
}
echo '</div><!-- /.chat -->
<div class="box-footer">
<div class="input-group">
<input class="form-control" placeholder="Type reply ..."/>
<div class="input-group-btn">
<button class="btn btn-success"><i class="fa fa-plus"></i></button>
</div>
</div></div>
</div>
</div>
</div>
</div>';
}
?>
</tbody>
<tfoot>
<tr>
<th style="text-align: center;">Job Title</th>
<th style="text-align: center;">Assigned To</th>
<th style="text-align: center;">Name Or Class</th>
<th style="text-align: center;">Priority</th>
<th style="text-align: center;">Date</th>
<th style="text-align: center;">Added By</th>
<th style="text-align: center;">Days Open</th>
<th style="text-align: center;">Replies</th>
<th style="text-align: center;">Actions</th>
</tr>
</tfoot>
我希望能够获取用户点击详细信息按钮的当前表行的ID并使用模式中的ID,我想在模式中运行另一个MYSQL查询并使用ID作为MYSQL WHERE。
例如
SELECT * FROM TABLE WHERE ID = "HERE WILL GO THE ID PULLED THROUGH"
我知道可以传递数据并只显示它,因为我已经这样做了,但我不想显示它我想在新的mysql查询中使用它。
如何根据表格行ID
获取模型中所有回复的列表答案 0 :(得分:0)
您可以编写此内容,以便单击“详细信息”按钮会触发ajax调用以获取单独的页面,例如/some/other/page?id=XXXX
。
在该单独的页面上,您使用传入的ID运行查询,然后返回内容(HTML / JSON等)并将其显示在模态中。