gpt4 book ai didi

php - 如何在 PHP 模型中获取行值

转载 作者:行者123 更新时间:2023-11-28 23:44:14 25 4
gpt4 key购买 nike

每当我单击该行时,我都想获取表的行值。在这里我必须在行中显示表格的数据..每当我点击该行时,我需要返回该行的其他变量值..

就像当我点击主题时,我需要显示来自数据库的各个主题的消息。

从数据库返回行值的 PHP 代码。

此代码段不会运行,因为它是 PHP 代码(只需将代码段添加到正确的格式中即可)

enter image description here enter image description here

在此图像中,弹出模型未显示正确的主题和消息。我需要弹出窗口中的这个特定主题和消息

Database Structure

<?php
include('../config/conn.php');

$sql = "SELECT * FROM helpdesk where user_id='$user_id'";
$result = $conn->query($sql);
$sr=1;
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$user_id=$row["user_id"];
$pooler_id=$row["pooler_id"];
$date=$row["date"];
$subject=$row["subject"];
$req=$row['req_id'];
$message=$row['message'];

$sql1 = "SELECT * FROM pooler where id='$pooler_id' ";
$result1 = $conn->query($sql1);
if ($result1->num_rows > 0) {
// output data of each row
while($row1 = $result1->fetch_assoc()) {
$username=$row1['user_name'];
$email=$row1['email'];
}
}

echo ' <tr>
<td>'.$sr.'</td>
<td>'.$username.'</td>
<td><a href="#" data-toggle="modal" data-target="#myModal">'.$subject.'</td>
<td>'.$date.'</td>


</tr>';
$sr++;
}
} else {
echo "0 results";
}
?>

模态 POP 代码,其中应显示发件人姓名、主题和消息。

  <!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title"> <?php echo $username; ?> <br><br> <?php echo $subject; ?> </h4>
</div>
<div class="modal-body">
<p>
<?php
echo $message;
?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

</div>

最佳答案

在你的 html 代码中

<td><a href="#" data-toggle="modal" data-target="#myModal" onclick="showData('.$pooler_id.')">'.$subject.'</td>

请在 javascript 函数中传递您的唯一 ID。

模态

  <!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">
<span id="user_name"><?php echo $username; ?></span> <br><br> <span id="subject"><?php echo $subject; ?></span> </h4>
</div>
<div class="modal-body">
<p id="msg">
<?php
echo $message;
?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>

脚本

<script>
function showData(pooler_id)
{
$.ajax({
type: POST,
url : 'some_file.php',
data: {pooler_id: pooler_id},
success: function(response){
var resp = JSON.parse(response);
$('#user_name').html(resp.user_name);
$('#subject').html(resp.subject);
$('#msg').html(resp.msg);
}
});
}
</script>

在 some_file.php 中

$pooler_id = $_POST['pooler_id'];
//get records of your primary key json_decode it
//get details from database
//this will be result fetched from database
$responseData['user_name'] = $name;
$responseData['subject'] = $subject;
$responseData['msg'] = $msg;


echo json_decode($responseData);

关于php - 如何在 PHP 模型中获取行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33864468/

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