我在同一用户的数据库表中有3个查询记录。当我查询返回并显示数据库表的最新查询时。我想返回3个查询,总是显示最新的查询,但有一个按钮,当单击时关闭显示的查询并打开上一个查询,依此类推,直到没有进一步的查询。通过这种方式,我始终可以访问每次咨询中注册的有关用户的信息。
此时我返回查询如下:
<a name="view2" id="<?php echo $row["Id"]; ?>" data-toggle="modal" href="#dataModal1" class="btn btn-primary view_data2" />EGA</a>
<div id="dataModal1" class="modal fade" style="width:1000px;">
<div class="modal-dialog" style="width:1000px;">
<div class="modal-content" style="width:1000px;">
<div class="modal-header" style="width:1000px;">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><strong>Estado Geral e Autonomia</strong></h4>
</div>
<div class="container"></div>
<div class="modal-body" id="employee_detail1">
</div>
<div class="modal-footer">
<a href="#" class="btn btn-danger" data-dismiss="modal">Sair</a>
</div>
</div>
</div>
</div>
$(document).on('click', '.view_data2', function() {
var employee_id1 = $(this).attr("Id");
if (employee_id1 != '') {
$.ajax({
url: "./select2",
method: "POST",
data: {
employee_id1: employee_id1
},
success: function(data) {
console.log(data);
$('#employee_detail1').html(data);
$('#dataModal1').modal('show');
}
});
}
});
在select2页面上,我有以下代码:
if(isset($_POST["employee_id1"]))
{
$output = '';
$query = "SELECT * FROM centrodb.PsicUtentes WHERE centrodb.PsicUtentes.Id = '".$_POST["employee_id1"]."'";
$result = mysqli_query($conn, $query);
$output;
while($row = mysqli_fetch_array($result))
{
$output .= '
<h4 class="modal-title">Identificação do Utente</h4>
<form method="post" id="insert_form2">
<fieldset class="grupo">
<table class="campo" cellspacing="10">
<tr>
<td>
<label>Data</label>
<input type="text" id="Data1" name="Data" class="form-control" value="'.$row["Data"].'" style="width:150px;" />
</td>
<td>
<label>Código Utente</label>
<input type="number" id="CodigoUtente1" name="CodigoUtente" value="'.$row["CodigoUtente"].'" class="form-control" style="width:100px;"/>
</td>
<td>
<label>Nome Utente</label>
<input type="text" id="Nome1" name="Nome" value="'.$row["Nome"].'" class="form-control" class="form-control" style="width:400px;"/>
</td>
<td>
<label>Data Nascimento</label>
<input type="date" id="DataNasc1" name="DataNasc" value="'.$row["DataNasc"].'" class="form-control" style="width:150px;"/>
</td>
</tr>
</table>
</fieldset>
</form>
';
}
$output;
echo $output;
}
当我有三个查询时,我会用页面显示图像:
我想要一个像红色包围的按钮,每当我点击时,我关闭显示的查询信息并打开上一个查询。
解决方案我正在尝试。
<script type="text/javascript">
$(document).ready(function(){
$('.conteudo').hide();
$('.exibir').each(function(i){
$(this).click(function(){
$('.conteudo').each(function(j){
if(i == j) $(this).show('slow');
});
});
});
$('.ocultar').each(function(i){
$(this).click(function(){
$('.conteudo').each(function(j){
if(i == j) $(this).hide('slow');
});
});
});
});
</script>
if(isset($_POST["employee_id1"]))
{
$output = '';
$query = "SELECT * FROM centrodb.PsicUtentes WHERE centrodb.PsicUtentes.Id = '".$_POST["employee_id1"]."'";
$result = mysqli_query($conn, $query);
$output;
while($row = mysqli_fetch_array($result))
{
$output .= '
<h4 class="modal-title">Identificação do Utente</h4>
<div>
<a class="exibir" href="#">Ver</a>--
<a href="#" class="ocultar">Ocultar</a>
</div>
<div class="conteudo">
<form method="post" id="insert_form2">
<fieldset class="grupo">
<table class="campo" cellspacing="10">
<tr>
<td>
<label>Data</label>
<input type="text" id="Data1" name="Data" class="form-control" value="'.$row["Data"].'" style="width:150px;" />
</td>
<td>
<label>Código Utente</label>
<input type="number" id="CodigoUtente1" name="CodigoUtente" value="'.$row["CodigoUtente"].'" class="form-control" style="width:100px;"/>
</td>
<td>
<label>Nome Utente</label>
<input type="text" id="Nome1" name="Nome" value="'.$row["Nome"].'" class="form-control" class="form-control" style="width:400px;"/>
</td>
<td>
<label>Data Nascimento</label>
<input type="date" id="DataNasc1" name="DataNasc" value="'.$row["DataNasc"].'" class="form-control" style="width:150px;"/>
</td>
</tr>
</table>
</fieldset>
</form>
<div>
';
}
$output;
echo $output;
}
这就是它的工作原理,但我仍然希望做得更好。我看到第一个记录,但是当我看到第二个记录时,第一个记录始终打开,当我打开第二个记录时应该隐藏。单击视图时会打开第二条记录,单击“隐藏”时会隐藏。另外我想要编辑和新按钮,总是根据我打开的div和我的项目,如果有两个注册表打开项目开头的两个按钮,应该打开我打开div,我在图像中显示:
当我第一次打开时:
当我看到第一张唱片时:
当我看到第二条记录时:
您可以做的是隐藏您的模式在您的HTML内容中,并用您的ajax填充它,然后一旦您有可以显示它的数据,您可以这样做:
你的PHP脚本:
if (isset($_POST["action"])) {
$action = $_POST["action"];
switch ($action) {
case 'SLC':
if (isset($_POST["id"])) {
$id = $_POST["id"];
if (is_int($id)) {
$query = "select * from client where clientId = '$id' ";
$update = mysqli_query($mysqli, $query);
$response = array();
while($row = mysqli_fetch_array($update)){
.......
// you need to fill the response array here with the info you
//want to display and send it with json encode later
}
echo json_encode($response);
}
}
break;
}
}
其中action可以是您想要执行的命令SLC,UPD,DEL等,id是一个参数
然后在你的ajax:
function getInfo(id) {
return $.ajax({
type: "POST",
url: "getInfo.php",
data: { action: "SLC", id:id }
})
}
然后像这样称呼它:
getInfo(id).done(function(response){
var data=JSON.parse(response);
if (data != null) {
$('#form_id').trigger("reset");
//fill your modal form using your data and display the modal after reset the form
$("#modal").show();
}
})
希望能帮助到你