gpt4 book ai didi

php - 从 PHP 循环获取 ID 并在 Bootstrap 模式的 MYSQL 查询中使用

转载 作者:行者123 更新时间:2023-11-29 22:59:03 24 4
gpt4 key购买 nike

我有一个 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 哪里。

例如

SELECT * FROM TABLE WHERE ID = "HERE WILL GO THE ID PULLED THROUGH"

我知道可以传递数据并只显示它,因为我已经这样做了,但我不想显示它,我想在新的 mysql 查询中使用它。

如何根据表行 ID 获取模型中所有回复的列表

最佳答案

您可以编写此代码,以便单击“详细信息”按钮会触发 ajax 调用来获取单独的页面,例如/some/other/page?id=XXXX

在该单独的页面上,您可以使用传入的 ID 运行查询,然后返回内容(HTML/JSON 等)并将其显示在模式中。

关于php - 从 PHP 循环获取 ID 并在 Bootstrap 模式的 MYSQL 查询中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28588951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com