当我想详细查看数据行时遇到问题。下面是系统流程:
1)在dashboard_engineer.php,有3个选择选项,分别是团队,时间和时间。
2)用户需要选择3个选择选项,然后按“搜索”按钮以显示结果。
3)结果将显示在dashboard_engineer2.php。
4)结果将显示所有数据行,并且每一行包含一个“查看”按钮,可以详细查看数据行。
我的问题仅在第一个数据行中。当我点击“查看”按钮时,它将使用空数据重定向到dashboard_engineer2.php。但是对于第二个数据以及下一个数据,我可以查看所选数据的详细信息。
这仅发生在过滤后显示的第一个数据上。下面是我的代码。
dashboard_engineer.php
<?php
$smt = $conn->prepare("
SELECT *
FROM ot_team t
JOIN ot_users u
ON t.team_id = u.team_id
WHERE u.roles_id = 7
AND u.team_id <> 1
ORDER
BY u.fullname ASC
");
$smt->execute();
$data = $smt->fetchAll();
?>
<form method = 'post' action = 'dashboard_engineer2.php' >
<td width="40%">
<select class="form-control" name="team" id="team" required>
<option value="">Please select...</option>
<?php foreach ($data as $row2): ?>
<option value= <?php echo $row2["team_id"]; ?> ><?php echo $row2["fullname"]; ?></option>
<?php endforeach ?>
</select>
</td>
<td width="1%"></td>
<td width="20%"><input type="text" name="from" id="from" class="form-control" placeholder="From" required></td>
<td width="1%"></td>
<td width="20%"><input type="text" name="to" id="to" class="form-control" placeholder="To" required></td>
<td width="1%"></td>
<td width="10%"><button type="submit" value="Search" class="btn btn-primary" >Send</button><td>
</form>
<script>
$(document).ready(function(){
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd'
});
$(function(){
$("#from").datepicker().attr("autocomplete", "off");;
$("#to").datepicker().attr("autocomplete", "off");;
});
});
</script>
dashboard_engineer2.php
<?php
if(isset($_REQUEST["from"], $_REQUEST["to"], $_REQUEST["team"])){
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$team = $_REQUEST['team'];
$result = '';
$query = "
SELECT *
FROM ot_report r
LEFT
JOIN ot_users u
ON r.badgeid = u.badgeid
WHERE u.team_id = '".$team."'
AND report_date BETWEEN '".$from."' AND '".$to."'
ORDER
BY r.report_id DESC
";
$sql = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$sql -> execute();
if($sql->rowCount() > 0){
echo'
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "10%"><input type="checkbox" id="checkAl"> All</th>
<th width = "3%">id</th>
<th width = "15%">Date</th>
<th width = "30%">Task Name</th>
<th width = "10%">Status</th>
<th colspan = "2" width = "7%">Action</th>
</tr>
</thead>
<tbody>';
$i=0;
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$datereport = $row['report_date'];
$datereport2 = strtotime($datereport);
$report_date = date('d M Y', $datereport2);
$report_id = $row["report_id"];
echo'<tr>';
echo '<td><input type="checkbox" id="checkItem" name="check[]" value='.$row['report_id'].'></td>';
echo '<td>'.$report_id.'</td>';
echo '<td>'.$report_date.'</td>';
echo '<td>'.$row["task_name"].'</td>';
echo '<td align="center"><strong>'.$row["report_status"].'</strong></td>';
echo '<td align="center">';
echo '<form action = "view_task/view_task.php" method = "post">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-primary">View</button>';
echo '</form>';
echo "<form action = 'delete.php' method = 'post' onClick=\"return confirm('Do you want to remove team?')\">";
echo '<input type = "hidden" name = "from" value = "'.$from.'">';
echo '<input type = "hidden" name = "to" value = "'.$to.'">';
echo '<input type = "hidden" name = "team" value = "'.$team.'">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-danger">Delete</button>';
echo '</form>';
echo '</td>';
echo '</tr>';
$i++;
}
echo '<tr>';
echo '<td><p align="center"><button type="submit" class="btn-danger btn-sm" name="save">DELETE</button></p></td>';
echo '</tr>';
echo '</form>';
}
else
{
echo '
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "5%">id</th>
<th width = "12%">Date</th>
<th width = "23%">Task Name</th>
<th width = "10%">Status</th>
<th width = "7%">Action</th>
</tr>
<tr>
<td colspan="5">No report found</td>
</tr>';
}
echo '</body></table></div></div>';
}
?>
view_task.php
<?php
require_once "../../../../config/configPDO.php";
require_once "../../../../config/check.php";
if (isset ($_POST['report_id'])) {
$report_id = $_POST['report_id'];
}else if (isset ($_GET['report_id'])) {
$report_id = $_GET['report_id'];
}else {
die ("ID NOT DEFINED");
}
$sql = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid LEFT JOIN ot_team ON ot_team.team_id = ot_users.team_id WHERE report_id = :report_id";
$query = $conn->prepare($sql);
$query->execute(array(':report_id' => $report_id));
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$report_id = $row["report_id"];
$task_name = $row["task_name"];
}
?>
<form action="update_task_name.php" method="POST">
<td><b>Task Name</b></td>
<td colspan = '2'><input type="text" class="form-control" name="task_name" value="<?php echo $task_name; ?>"/></td> //line 50
<input type="hidden" name="report_id" value="<?php echo $report_id ?>">
<td><input type="submit" class="btn btn-primary btn-block" value = "Save" onclick="confirm('Are you sure?')"></td>
</form>
有人可以帮忙吗?