我现在正在做一个项目,一切都很好,CRUD函数都在工作。我有一个页面的class.user.php, viewsample.php和next.php。现在,我的问题是,我只想在viewsample。php中添加一个next按钮,如果我点击一个特定的记录或id它会在viewsample。php中显示那个人或id的记录。在viewsample。php中,我想添加一个next按钮因为一个id或person有很多细节不能放在一个窗口中,所以我想添加一个next按钮。当用户单击next按钮时,它将显示该特定人员或id的其他详细信息。我不想要发生的是,当我点击下一个按钮,它会转到下一个id..我想要的是留在当前id和显示该id或人的其他细节..有人能帮助我吗?
class.user.php
public function dataview($query)
{
$stmt = $this->db->prepare("SELECT * from login ORDER BY username");
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td> ".$row['user_id']." </td>";
echo "<td> ".$row['username']." </td>";
echo '<td><a target="_blank" onclick="pop_up(this)" href=VIEWSAMPLE.PHP?user_id='.$row['user_id'].'>'.$row["username"].'</a></td>';
echo "<td> ".$row['password']." </td>";
echo '<td><a style="float:left" target="_blank" href="update.php?user_id=' . $row["user_id"] . '>'.$row["username"].'"<input name="image" type="image" value="edit" onclick="pop_up(this)"><image src="image/EDIT.png" class="img-responsive" width="25px"></a>
<a style="float:left" href="delete.php?user_id=' . $row["user_id"] . '>" <input name="image" type="image" value="delete" onclick="return confirm(''are you sure?'')"><image src="image/DELETE.png" class="img-responsive" width="25px"></a></td>';
echo "</tr>";
}
}
else
{
echo "<tr>";
"<td>Nothing here...</td>";
"</tr>";
}
}
}
viewsample.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<body>
<a href="NEXT.php?user_id=id FROM login">Next</a>
<br />
<br />
<div id="Survey-view">
<div id="header">
</div>
<p><strong>INFORMATION</strong></p>
<hr />
<div id="main-frame">
<table id="information-content" cellspacing="0">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Province</th>
</tr>
<tbody>
<tr>
<td><?php echo $username; ?></td>
<td><?php echo $password; ?></td>
<td><?php echo $province; ?></td>
</tr>
</tbody>
</thead>
</table>
</div>
<br />
<br />
next.php
<?php
include_once 'dbconfig.php';
$username = isset($_GET['username']) ? $_GET['username'] : '';
$password = isset($_GET['password']) ? $_GET['password'] : '';
$province = isset($_GET['province']) ? $_GET['province'] : '';
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
extract($crud->getID($user_id));
}
?>
<p><strong>INFORMATION</strong></p>
<hr />
<div id="main-frame">
<table id="information-content" cellspacing="0">
<thead>
<tr>
<th>Username</th>
<th>Password</th>
<th>Province</th>
</tr>
<tbody>
<tr>
<td><?php echo $username; ?></td>
<td><?php echo $password; ?></td>
<td><?php echo $province; ?></td>
</tr>
</tbody>
</thead>
</table>
</div>
您可能希望使用AJAX
来获取同一用户的新信息,但是根据有多少数据,您可以一次呈现所有信息并使用javascript来隐藏和显示不同的部分。也许类似于这个(我正在使用jQuery,因为我的javascript知识甚至比我有效使用jQuery的能力更少,我相信更熟练的jQuery/javascript的人可以做得更好):
http://jsfiddle.net/qmzj7tsw/
样式:
<style>
.default-show {
display: block !important;
}
.stuff {
display: none;
}
.btn-next {
cursor: pointer;
}
</style>
HTML: <div class="btn-next">NEXT</div>
<ul id="userInfo">
<li class="stuff default-show">Stuff1</li>
<li class="stuff">Stuff2</li>
<li class="stuff">Stuff3</li>
</ul>
jQuery: <script>
$(document).ready(function() {
$(".btn-next").click(function() {
var curr = $(".default-show");
var next = curr.next();
if(next.attr("class") !== 'stuff') {
var all_btns = $("#userInfo").children("li");
curr.removeClass("default-show");
curr = $(all_btns[0]);
curr.addClass("default-show");
}
else {
curr.removeClass("default-show");
curr.next().addClass("default-show");
}
});
});
</script>