|
|
|
บันทึกวันที่ 26 ก.ย. 2564 ทำไมใน DB ลงเป็น 1632589200 ครับ |
|
|
|
|
|
|
|
เปลี่ยน field type เป็น datetime
วันที่ เวลา ใน database มันเก็บเป็น ตัวเลข โดย 0 คือ 1970-01-01 00:00:00
0 คือ 1970-01-01 00:00:00
1 คือ 1970-01-01 00:00:01
2 คือ 1970-01-01 00:00:02
...
...
16...... คือ 2021......
ส่วนการแสดงผล ให้กำหนดด้วย field type
ปล. unixtime มีค่าเป็น วินาที
|
ประวัติการแก้ไข 2021-09-26 12:05:17
|
|
|
|
Date :
2021-09-26 12:04:20 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แสดงว่าปัญหาอยู่ที่ INPUT ครับ ลองดูว่ารับค่าอะไรมา ลอง echo ตัวแปรวันที่ออกมาดูค่าในนั้นครับ
จากนั้นก็เซ็ตค่าให้ตรง format ที่ต้องการแล้วก็เอาไปใส่ในคำสั่ง INSERT
|
|
|
|
|
Date :
2021-09-27 13:52:44 |
By :
{Cyberman} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code
แสดงว่าปัญหาอยู่ที่ INPUT ครับ ลองดูว่ารับค่าอะไรมา ลอง echo ตัวแปรวันที่ออกมาดูค่าในนั้นครับ
จากนั้นก็เซ็ตค่าให้ตรง format ที่ต้องการแล้วก็เอาไปใส่ในคำสั่ง INSERT
ในไฟล์นี้ น่าจะเกี่ยวไหมครับ
หากใช่ ควรปรับคำสั่งตรงไหนไหมครับ
Code (PHP)
<?php
include 'config1.php';
$updateFlag = 0;
?>
<div class="container">
<div class="row ">
<div class="col-md-12 col-lg-12">
<h1 class="page-header">Take Attendance</h1>
</div>
</div>
<div class="row text-center">
<div class="col-md-12 col-lg-12">
<form action="index.php" method="get" class="form-inline" id="subjectForm" data-toggle="validator">
<div class="form-group">
<label for="select" class="control-label">Subject:</label>
<?php
$query_subject = "SELECT subject.name, subject.id from subject
INNER JOIN user_subject WHERE user_subject.id = subject.id AND user_subject.uid = {$_SESSION['uid']} ORDER BY subject.name";
$sub=$conn->query($query_subject);
$rsub=$sub->fetchAll(PDO::FETCH_ASSOC);
echo "<select name='subject' class='form-control' required='required'>";
for($i = 0; $i<count($rsub); $i++)
{
if ($_GET['subject'] == $rsub[$i]['id']) {
echo"<option value='". $rsub[$i]['id']."' selected='selected'>".$rsub[$i]['name']."</option>";
}
else {
echo"<option value='". $rsub[$i]['id']."'>".$rsub[$i]['name']."</option>";
}
}
echo"</select>";
?>
</div>
<div class="form-group" data-provide="datepicker">
<label for="select" class="control-label">Date:</label>
<input type="date" class="form-control" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>" required>
</div>
<button type="submit" class="btn btn-danger" style='border-radius:0%;' name="sbt_stn"><i class="glyphicon glyphicon-filter"></i> Load</button>
</form>
<?php
if(isset($_GET['date']) && isset($_GET['subject'])) :
?>
<?php
$todayTime = time();
$submittedDate = strtotime($_GET['date']);
if ($submittedDate <= $todayTime) :
?>
<form action="index.php" method="post">
<div class="margin-top-bottom-medium">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center">Student ID</th>
<th class="text-center">Student's Name: Level: Room: No</th>
<th class="text-center"><input type="checkbox" class="chk-head" /> All Present</th>
</tr>
</thead>
<?php
$dat = $_GET['date'];
$ddate = strtotime($dat);
$sub=$_GET['subject'];
$que= "SELECT sid, aid, ispresent from attendance WHERE date =$ddate
AND id=$sub ORDER BY sid";
$ret=$conn->query($que);
$attData=$ret->fetchAll(PDO::FETCH_ASSOC);
if(count($attData))
{
$updateFlag=1;
}
else{
$updateFlag=0;
}
$qu = "SELECT student.sid, student.name, student.rollno from student INNER JOIN student_subject WHERE student.sid = student_subject.sid AND student_subject.id = {$_GET['subject']} ORDER BY student.sid";
$stu=$conn->query($qu);
$rstu=$stu->fetchAll(PDO::FETCH_ASSOC);
echo"<tbody>";
for($i = 0; $i<count($rstu); $i++)
{
echo"<tr>";
if($updateFlag) {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'>" ."<input type='hidden' name='att_id[]' value='" . $attData[$i]['aid'] . "'>". "</td>";
echo"<td>".$rstu[$i]['name']."</td>";
if(($rstu[$i]['sid'] == $attData[$i]['sid']) && ($attData[$i]['ispresent']))
{
echo "<td><input class='chk-present' checked type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
else
{
echo "<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
}
else {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'></td>";
echo"<td>".$rstu[$i]['name']."</td>";
echo"<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
echo"</tr>";
}
echo"</tbody>";
?>
</table>
<?php if($updateFlag) : ?>
<input type="hidden" name="updateData" value="1">
<?php else: ?>
<input type="hidden" name="updateData" value="0">
<?php endif; ?>
<input type="hidden" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>">
<input type="hidden" name="subject" value="<?php print isset($_GET['subject']) ? $_GET['subject'] : ''; ?>">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</form>
<?php
else :
?>
<p> </p>
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Sorry!</strong> Attendance cannot be recorded for future dates!.
</div>
<?php
endif;
?>
<?php endif;?>
<?php
if (isset($_POST['sbt_top'])) {
if(isset($_POST['updateData']) && ($_POST['updateData'] == 1) ) {
// prepare sql and bind parameters
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$attt_aid = $_POST['att_id'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
// UPDATE `attendance` SET `ispresent` = '1' WHERE `attendance`.`aid` = 79;
$stmtInsert = $conn->prepare("UPDATE attendance SET ispresent = :isMarked WHERE aid = :aid");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':isMarked', $p);
$stmtInsert->bindParam(':aid', $attt_aid[$j]);
$stmtInsert->execute();
//echo "data upadted";
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
else {
// prepare sql and bind parameters
$date = $_POST['date'];
$tstamp = strtotime($date);
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
$stmtInsert = $conn->prepare("INSERT INTO attendance (sid, date, ispresent, uid, id)
VALUES (:sid, :date, :ispresent, :uid, :id)");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':sid', $st_sid[$j]);
$stmtInsert->bindParam(':date', $tstamp);
$stmtInsert->bindParam(':ispresent', $p);
$stmtInsert->bindParam(':uid', $uid);
$stmtInsert->bindParam(':id', $id);
$stmtInsert->execute();
// echo "data upadted".$j;
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
}
?>
</div>
</div>
</div>
<script>
$('#subjectForm').validator();
</script>
|
ประวัติการแก้ไข 2021-09-27 20:59:05 2021-09-27 20:59:55
|
|
|
|
Date :
2021-09-27 20:58:02 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมแก้ code ตามนี้ แต่ใน DB แสดงค่าเฉพาะปี
หากต้องการให้แสดงวันและเดือนด้วยต้องปรับ code ตรงไหน อย่างไรครับ
Code (PHP)
<?php
include 'config1.php';
$updateFlag = 0;
?>
<div class="container">
<div class="row ">
<div class="col-md-12 col-lg-12">
<h1 class="page-header">Take Attendance</h1>
</div>
</div>
<div class="row text-center">
<div class="col-md-12 col-lg-12">
<form action="index.php" method="get" class="form-inline" id="subjectForm" data-toggle="validator">
<div class="form-group">
<label for="select" class="control-label">Subject:</label>
<?php
$query_subject = "SELECT subject.name, subject.id from subject
INNER JOIN user_subject WHERE user_subject.id = subject.id AND user_subject.uid = {$_SESSION['uid']} ORDER BY subject.name";
$sub=$conn->query($query_subject);
$rsub=$sub->fetchAll(PDO::FETCH_ASSOC);
echo "<select name='subject' class='form-control' required='required'>";
for($i = 0; $i<count($rsub); $i++)
{
if ($_GET['subject'] == $rsub[$i]['id']) {
echo"<option value='". $rsub[$i]['id']."' selected='selected'>".$rsub[$i]['name']."</option>";
}
else {
echo"<option value='". $rsub[$i]['id']."'>".$rsub[$i]['name']."</option>";
}
}
echo"</select>";
?>
</div>
<div class="form-group" data-provide="datepicker">
<label for="select" class="control-label">Date:</label>
<input type="date" class="form-control" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>" required>
</div>
<button type="submit" class="btn btn-danger" style='border-radius:0%;' name="sbt_stn"><i class="glyphicon glyphicon-filter"></i> Load</button>
</form>
<?php
if(isset($_GET['date']) && isset($_GET['subject'])) :
?>
<?php
$todayTime = time();
$submittedDate = strtotime($_GET['date']);
if ($submittedDate <= $todayTime) :
?>
<form action="index.php" method="post">
<div class="margin-top-bottom-medium">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center">Student ID</th>
<th class="text-center">Student's Name: Level: Room: No</th>
<th class="text-center"><input type="checkbox" class="chk-head" /> All Present</th>
</tr>
</thead>
<?php
$dat = $_GET['date'];
$ddate = strtotime($dat);
$sub=$_GET['subject'];
$que= "SELECT sid, aid, ispresent from attendance WHERE date =$ddate
AND id=$sub ORDER BY sid";
$ret=$conn->query($que);
$attData=$ret->fetchAll(PDO::FETCH_ASSOC);
if(count($attData))
{
$updateFlag=1;
}
else{
$updateFlag=0;
}
$qu = "SELECT student.sid, student.name, student.rollno from student INNER JOIN student_subject WHERE student.sid = student_subject.sid AND student_subject.id = {$_GET['subject']} ORDER BY student.sid";
$stu=$conn->query($qu);
$rstu=$stu->fetchAll(PDO::FETCH_ASSOC);
echo"<tbody>";
for($i = 0; $i<count($rstu); $i++)
{
echo"<tr>";
if($updateFlag) {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'>" ."<input type='hidden' name='att_id[]' value='" . $attData[$i]['aid'] . "'>". "</td>";
echo"<td>".$rstu[$i]['name']."</td>";
if(($rstu[$i]['sid'] == $attData[$i]['sid']) && ($attData[$i]['ispresent']))
{
echo "<td><input class='chk-present' checked type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
else
{
echo "<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
}
else {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'></td>";
echo"<td>".$rstu[$i]['name']."</td>";
echo"<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
echo"</tr>";
}
echo"</tbody>";
?>
</table>
<?php if($updateFlag) : ?>
<input type="hidden" name="updateData" value="1">
<?php else: ?>
<input type="hidden" name="updateData" value="0">
<?php endif; ?>
<input type="hidden" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>">
<input type="hidden" name="subject" value="<?php print isset($_GET['subject']) ? $_GET['subject'] : ''; ?>">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</form>
<?php
else :
?>
<p> </p>
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Sorry!</strong> Attendance cannot be recorded for future dates!.
</div>
<?php
endif;
?>
<?php endif;?>
<?php
if (isset($_POST['sbt_top'])) {
if(isset($_POST['updateData']) && ($_POST['updateData'] == 1) ) {
// prepare sql and bind parameters
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$attt_aid = $_POST['att_id'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
// UPDATE `attendance` SET `ispresent` = '1' WHERE `attendance`.`aid` = 79;
$stmtInsert = $conn->prepare("UPDATE attendance SET ispresent = :isMarked WHERE aid = :aid");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':isMarked', $p);
$stmtInsert->bindParam(':aid', $attt_aid[$j]);
$stmtInsert->execute();
//echo "data upadted";
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
else {
// prepare sql and bind parameters
$date = $_POST['date'];
//$tstamp = strtotime($date);
$tstamp = NULL;
if ( ! empty($date)) {
$tstamp = $date;
}
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
$stmtInsert = $conn->prepare("INSERT INTO attendance (sid, date, ispresent, uid, id)
VALUES (:sid, :date, :ispresent, :uid, :id)");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':sid', $st_sid[$j]);
$stmtInsert->bindParam(':date', $tstamp);
$stmtInsert->bindParam(':ispresent', $p);
$stmtInsert->bindParam(':uid', $uid);
$stmtInsert->bindParam(':id', $id);
$stmtInsert->execute();
// echo "data upadted".$j;
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
}
?>
</div>
</div>
</div>
<script>
$('#subjectForm').validator();
</script>
|
|
|
|
|
Date :
2021-09-30 22:07:30 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quote:echo $date;
ผมใส่ คำสั่ง echo $date; แล้วลองบันทึก ยังขึ้นเฉพาะ ปี เช่นเดิมครับ
Code (PHP)
<?php
include 'config1.php';
$updateFlag = 0;
?>
<div class="container">
<div class="row ">
<div class="col-md-12 col-lg-12">
<h1 class="page-header">Take Attendance</h1>
</div>
</div>
<div class="row text-center">
<div class="col-md-12 col-lg-12">
<form action="index.php" method="get" class="form-inline" id="subjectForm" data-toggle="validator">
<div class="form-group">
<label for="select" class="control-label">Subject:</label>
<?php
$query_subject = "SELECT subject.name, subject.id from subject
INNER JOIN user_subject WHERE user_subject.id = subject.id AND user_subject.uid = {$_SESSION['uid']} ORDER BY subject.name";
$sub=$conn->query($query_subject);
$rsub=$sub->fetchAll(PDO::FETCH_ASSOC);
echo "<select name='subject' class='form-control' required='required'>";
for($i = 0; $i<count($rsub); $i++)
{
if ($_GET['subject'] == $rsub[$i]['id']) {
echo"<option value='". $rsub[$i]['id']."' selected='selected'>".$rsub[$i]['name']."</option>";
}
else {
echo"<option value='". $rsub[$i]['id']."'>".$rsub[$i]['name']."</option>";
}
}
echo"</select>";
?>
</div>
<div class="form-group" data-provide="datepicker">
<label for="select" class="control-label">Date:</label>
<input type="date" class="form-control" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>" required>
</div>
<button type="submit" class="btn btn-danger" style='border-radius:0%;' name="sbt_stn"><i class="glyphicon glyphicon-filter"></i> Load</button>
</form>
<?php
if(isset($_GET['date']) && isset($_GET['subject'])) :
?>
<?php
$todayTime = time();
$submittedDate = strtotime($_GET['date']);
if ($submittedDate <= $todayTime) :
?>
<form action="index.php" method="post">
<div class="margin-top-bottom-medium">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th class="text-center">Student ID</th>
<th class="text-center">Student's Name: Level: Room: No</th>
<th class="text-center"><input type="checkbox" class="chk-head" /> All Present</th>
</tr>
</thead>
<?php
$dat = $_GET['date'];
$ddate = strtotime($dat);
$sub=$_GET['subject'];
$que= "SELECT sid, aid, ispresent from attendance WHERE date =$ddate
AND id=$sub ORDER BY sid";
$ret=$conn->query($que);
$attData=$ret->fetchAll(PDO::FETCH_ASSOC);
if(count($attData))
{
$updateFlag=1;
}
else{
$updateFlag=0;
}
$qu = "SELECT student.sid, student.name, student.rollno from student INNER JOIN student_subject WHERE student.sid = student_subject.sid AND student_subject.id = {$_GET['subject']} ORDER BY student.sid";
$stu=$conn->query($qu);
$rstu=$stu->fetchAll(PDO::FETCH_ASSOC);
echo"<tbody>";
for($i = 0; $i<count($rstu); $i++)
{
echo"<tr>";
if($updateFlag) {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'>" ."<input type='hidden' name='att_id[]' value='" . $attData[$i]['aid'] . "'>". "</td>";
echo"<td>".$rstu[$i]['name']."</td>";
if(($rstu[$i]['sid'] == $attData[$i]['sid']) && ($attData[$i]['ispresent']))
{
echo "<td><input class='chk-present' checked type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
else
{
echo "<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
}
else {
echo"<td>".$rstu[$i]['rollno']."<input type='hidden' name='st_sid[]' value='" . $rstu[$i]['sid'] . "'></td>";
echo"<td>".$rstu[$i]['name']."</td>";
echo"<td><input class='chk-present' type='checkbox' name='chbox[]' value='" . $rstu[$i]['sid'] . "'></td>";
}
echo"</tr>";
}
echo"</tbody>";
?>
</table>
<?php if($updateFlag) : ?>
<input type="hidden" name="updateData" value="1">
<?php else: ?>
<input type="hidden" name="updateData" value="0">
<?php endif; ?>
<input type="hidden" name="date" value="<?php print isset($_GET['date']) ? $_GET['date'] : ''; ?>">
<input type="hidden" name="subject" value="<?php print isset($_GET['subject']) ? $_GET['subject'] : ''; ?>">
<button type="submit" class="btn btn-success btn-block" style='border-radius:0%;' name="sbt_top"><i class="glyphicon glyphicon-ok-sign"></i> Save Attendance</button>
</form>
<?php
else :
?>
<p> </p>
<div class="alert alert-dismissible alert-danger">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Sorry!</strong> Attendance cannot be recorded for future dates!.
</div>
<?php
endif;
?>
<?php endif;?>
<?php
if (isset($_POST['sbt_top'])) {
if(isset($_POST['updateData']) && ($_POST['updateData'] == 1) ) {
// prepare sql and bind parameters
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$attt_aid = $_POST['att_id'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
// UPDATE `attendance` SET `ispresent` = '1' WHERE `attendance`.`aid` = 79;
$stmtInsert = $conn->prepare("UPDATE attendance SET ispresent = :isMarked WHERE aid = :aid");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':isMarked', $p);
$stmtInsert->bindParam(':aid', $attt_aid[$j]);
$stmtInsert->execute();
//echo "data upadted";
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
else {
// prepare sql and bind parameters
$date = $_POST['date'];
echo $date;
//$tstamp = strtotime($date);
$tstamp = NULL;
if ( ! empty($date)) {
$tstamp = $date;
}
$id = $_POST['subject'];
$uid = $_SESSION['uid'];
$p = 0;
$st_sid = $_POST['st_sid'];
$ispresent = array();
if (isset($_POST['chbox'])) {
$ispresent = $_POST['chbox'];
}
for($j = 0; $j < count($st_sid); $j++)
{
//echo "hii";
$stmtInsert = $conn->prepare("INSERT INTO attendance (sid, date, ispresent, uid, id)
VALUES (:sid, :date, :ispresent, :uid, :id)");
if (count($ispresent)) {
$p = (in_array($st_sid[$j], $ispresent)) ? 1 : 0;
}
$stmtInsert->bindParam(':sid', $st_sid[$j]);
$stmtInsert->bindParam(':date', $tstamp);
$stmtInsert->bindParam(':ispresent', $p);
$stmtInsert->bindParam(':uid', $uid);
$stmtInsert->bindParam(':id', $id);
$stmtInsert->execute();
// echo "data upadted".$j;
}
echo '<p> </p><div class="alert alert-dismissible alert-success">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Well done!</strong> Attendance Recorded Successfully!.
</div>';
}
}
?>
</div>
</div>
</div>
<script>
$('#subjectForm').validator();
</script>
|
|
|
|
|
Date :
2021-10-01 10:15:07 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมใส่สูตรคำนวณค่าในคอลัมน์ Date แต่ได้ค่า วันเดือนปี ที่ต่างจากค่าในคอลัมน์ timestamp
ทั้งที่วันเดือนปีที่เลือกบันทึกการเข้าชั้นเรียน (Date) เป็นวันเดียวกันกับวันที่คลิกบันทึก (timestamp) ครับ
พอจะทราบสาเหตุไหมครับว่า ทำไมค่าใน Date กับ timestamp ถึงได้วันเดือนปีที่ต่างกัน
|
|
|
|
|
Date :
2021-10-05 06:31:23 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หากผม export DB มาเป็น excel พอจะมีสูตรคำนวณค่าใน Date ให้เป็นค่ารูปแบบ ปี เดือน วัน ไหม ครับ
Code (PHP)
echo date('Y-m-d H:i:s', 1632675600);
//2021-09-27 00:00:00
|
|
|
|
|
Date :
2021-10-05 19:07:48 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ต้องเอาคำสั่งนี้ไปววางที่บรรทัดไหนครับ
Code (PHP)
SELECT DATE_FORMAT(FROM_UNIXTIME(1632675600), '%Y-%m-%d %H:%i:%s');
SELECT DATE_FORMAT(FROM_UNIXTIME(1632675600), '%Y-%m-%d');
SELECT DATE_FORMAT(FROM_UNIXTIME(`field_name`), '%Y-%m-%d %H:%i:%s');
SELECT DATE_FORMAT(FROM_UNIXTIME(`date`), '%Y-%m-%d');
|
|
|
|
|
Date :
2021-10-07 05:01:09 |
By :
ajsudkedt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|