php 根据行的值,数据未传输到bootstarp模态

mnowg1ta  于 2023-03-07  发布在  PHP
关注(0)|答案(1)|浏览(100)

我有一个显示记录的几个字段的页面。在每条记录前面有一个按钮视图。当我单击视图按钮时,它会打开一个引导模式。此模式显示该记录的完整详细信息。基本上,我想使用js传输两个变量id和fy。模态正在显示,但没有给出正确的输出。它总是显示值'1'代替了fy和id值。我的代码中有什么错误。

<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['login'])==0)
{   
header('location:index.php');
}
else{ 

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="" />
<meta name="author" content="" />
<!-- BOOTSTRAP CORE STYLE  -->
<link href="assets/css/bootstrap.css" rel="stylesheet" />

</head>
<body>

<!-- MENU SECTION END-->
<div class="content-wrapper">
<div class="container">
<div class="row pad-botm">
<div class="col-md-12">
<h4 class="header-line">Manage Letter</h4>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- Advanced Tables -->
<div class="panel panel-default">
<div class="panel-heading">
Outwards Letter
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr style="text-align:center">
<th style="width:25px;">Sl.No.</th>
<th style="text-align:center">FY</th>
<th style="text-align:center">Addressee </th>
</tr>
</thead>
<tbody>
<?php 
$sid=$_SESSION['stdid'];
$sql="SELECT * from tbloutwards where Dep='$sid' ORDER BY id ";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{               ?>                                     
<tr class="odd gradeX">
<td class="center"><?php echo htmlentities($cnt);?></td>
<td class="center"><?php echo htmlentities($result->fy);?></td>
<td class="center"><?php echo htmlentities($result->Dep);?></td>
<td class="center"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">View</button></t>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<?php
$sid=$_post['id'];
$fy=$_post['fy'];
$sql="SELECT * from tbloutwards where fy='$fy' and id='$id'  " ;
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
echo print_r($results['fy']);

?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">CLOSE</button>

</td>
</tr>
<?php $cnt=$cnt+1;}}} ?>                                      
</tbody>
</table>
</div>
<script>
$(document).ready(function () {             
$('.open-my-modal').click(function(){
$('#id').html($(this).data('id'));
$('#fy').html($(this).data('fy'));
$('#dep').html($(this).data('dep'));

// show Modal
$('#myModal').modal('show');
});
});
</script> 
</div>
</div>
<script src="assets/js/jquery-1.10.2.js"></script>
<!-- BOOTSTRAP SCRIPTS  -->
<script src="assets/js/bootstrap.js"></script>
<!-- DATATABLE SCRIPTS  -->
<script src="assets/js/dataTables/jquery.dataTables.js"></script>
<script src="assets/js/dataTables/dataTables.bootstrap.js"></script>
<!-- CUSTOM SCRIPTS  -->
<script src="assets/js/custom.js"></script>
</body>
</html>
qnakjoqk

qnakjoqk1#

将PDO::FETCH_OBJ替换为PDO::FETCH_ASSOC,并使用fetchAll来获取:

$sid=$_post['id'];
$fy=$_post['fy'];
$sql="SELECT * from tbloutwards where fy='$fy' and id='$id'  " ;
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetch(PDO::FETCH_ASSOC);
echo print_r($results['fy']);

只有这样,$results才会包含一个关联数组,其中才会有一个键'fy'。

相关问题