此代码工作正常,但我不希望显示btnvalue为零和一个,而我想要显示Log-In注销以检查btnvalue为零和一。 帮助我了解检查值的正确语法或td标签内的if / else条件。
<?php
if(isset($_POST["from_date"] , $_POST["to_date"]))
{
$connect = mysqli_connect("localhost", "root", "root", "attendance");
$output = '';
$query ="SELECT * FROM logintime WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' UNION SELECT * FROM logouttime WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'
";
$result = mysqli_query($connect, $query);
$output .= '
<table class="table table-bordered">
<tr>
<th>EMP-ID</th>
<th>STATUS</th>
<th>TIME</th>
<th>DATE</th>
<th>DAILY JOB</th>
</tr>
';
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
$output .= '
<tr>
<td>'. $row["techid"] .'</td>
<td>'. $row["btnvalue"].'</td>
<td>'. $row["time"] .'</td>
<td>'. $row["date"] .'</td>
<td>'. $row["comment"] .'</td>
</tr>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5">No Attendance Found</td>
</tr>
';
}
$output .= '</table>';
echo $output;
}
?>
答案 0 :(得分:0)
尝试在while循环中尝试以下代码集:
$output .= '
<tr>
<td>'. $row["techid"] .'</td>
<td><input type="checkbox" value="'.$row["btnvalue"].'" '.($row["btnvalue"] == 1)? 'checked' : '' .' >'.($row["btnvalue"] == 1)? 'Logged In' : 'Logged Out' .'</td>
<td>'. $row["time"] .'</td>
<td>'. $row["date"] .'</td>
<td>'. $row["comment"] .'</td>
</tr>
';
如果$row["btnvalue"]
为1:则选中其显示,否则为未选中。
在我的代码中,我将1视为已登录,将0视为已退出
答案 1 :(得分:0)
以下内容将显示基于btnvalue
的登录或注销:
<?php
if(isset($_POST["from_date"] , $_POST["to_date"]))
{
$connect = mysqli_connect("localhost", "root", "root", "attendance");
$output = '';
$query ="SELECT * FROM logintime WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' UNION SELECT * FROM logouttime WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'
";
$result = mysqli_query($connect, $query);
$output .= '
<table class="table table-bordered">
<tr>
<th>EMP-ID</th>
<th>STATUS</th>
<th>TIME</th>
<th>DATE</th>
<th>DAILY JOB</th>
</tr>
';
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
$output .= '
<tr>
<td>'. $row["techid"] .'</td>
<td>'.(($row["btnvalue"]=='0') ? 'Log-in':'Log-out').'</td>
<td>'. $row["time"] .'</td>
<td>'. $row["date"] .'</td>
<td>'. $row["comment"] .'</td>
</tr>
';
}
}
else
{
$output .= '
<tr>
<td colspan="5">No Attendance Found</td>
</tr>
';
}
$output .= '</table>';
echo $output;
}
?>