ผมเขียน php บันทึกเวลาเข้าออก แต่พอรันดูแล้ว จับเวลาไม่ได้
รบกวนช่วยหาวิธีแก้ไขให้หน่อยครับ
ช่วยบอกโค้ดที่ทำให้ จับเวลา Login และ Logout ด้วยครับ
ภาษาไทย สำหรับ phpBB เวอร์ชั่นล่าุด คือ 3.2.2
มาแล้วโหลดได้เลย
มาแล้วโหลดได้เลย
รบกวนผู้รู้ แนะนำโค้ดที่ใช้ในการบันทึกเวลา Login และ Logout
Moderator: phpbb, mindphp, ผู้ดูแลกระดาน
มือใหม่
อันนี้ไฟล์ login ครับ
<?
session_start();
$_SESSION[sess_userid]=session_id();
//$_SESSION[sess_idonout]=session_idonout();
$_SESSION[sess_name]=session_name();
$_SESSION[sess_username]=$user_reg;
include "function.php";
include "member_chksession.php";
$sess_username=$sess_username;
$time_now=time();
$time_in=$time_now ;
$start_date=date("Y-m-d");
$start_time=date("H:i:s");
$out_date=date("Y-m-d");
$out_time=date("H:i:s");
session_start();
$sess_id=session_id();
include "connect.php";
$sql="insert into tb_useronline values(' ','$sess_username','$time_in','$start_date','$start_time')";
mysql_db_query($dbname,$sql);
// $useronline=mysql_num_rows($result);
mysql_close();
?>
ส่วนอันนี้คือ ไฟล์ logout
<?
session_start();
include "connect.php";
$time_now=time();
$time_out=$time_now ;
$out_date=date("Y-m-d");
$out_time=date("H:i:s");
session_start();
$sess_id=session_id();
include "connect.php";
$sql="insert into tb_useroutline values('$sess_id','$sess_username','$time_out','out_date','$out_time')";
mysql_db_query($dbname,$sql);
mysql_close();
?>
ซึ่งสามารถเก็บเวลาและวันที่ในดาต้าเบสได้ แต่เมื่อ Select ข้อมูลด้วยคำสั่งดังนี้
$sql="select * from tb_member , tb_useronline , tb_useroutline where (tb_member.username=tb_useronline.user_online) and (tb_member.username=tb_useroutline.user_outline) and (tb_useronline.user_online=tb_useroutline.user_outline)and (start_date ='$start_date') group by start_time order by start_date ";
ข้อมูลที่ได้มา คือ Code,Name,LoginDate,LoginTime,LogoutTime
ปัญหาคือหนึ่ง Record เวลาLogin นั้น ตรงขึ้นครบทุกคนแต่เวลา Logout นั้นจะโชว์ข้อมูลครั้งแรกเท่านั้น ไม่ว่าจะLogin กี่ครั้ง Logout กี่ครั้ง รบกวนสอบถามด้วยค่ะว่าควรจะแก้โค้ด Select ยังไง
<?
session_start();
$_SESSION[sess_userid]=session_id();
//$_SESSION[sess_idonout]=session_idonout();
$_SESSION[sess_name]=session_name();
$_SESSION[sess_username]=$user_reg;
include "function.php";
include "member_chksession.php";
$sess_username=$sess_username;
$time_now=time();
$time_in=$time_now ;
$start_date=date("Y-m-d");
$start_time=date("H:i:s");
$out_date=date("Y-m-d");
$out_time=date("H:i:s");
session_start();
$sess_id=session_id();
include "connect.php";
$sql="insert into tb_useronline values(' ','$sess_username','$time_in','$start_date','$start_time')";
mysql_db_query($dbname,$sql);
// $useronline=mysql_num_rows($result);
mysql_close();
?>
ส่วนอันนี้คือ ไฟล์ logout
<?
session_start();
include "connect.php";
$time_now=time();
$time_out=$time_now ;
$out_date=date("Y-m-d");
$out_time=date("H:i:s");
session_start();
$sess_id=session_id();
include "connect.php";
$sql="insert into tb_useroutline values('$sess_id','$sess_username','$time_out','out_date','$out_time')";
mysql_db_query($dbname,$sql);
mysql_close();
?>
ซึ่งสามารถเก็บเวลาและวันที่ในดาต้าเบสได้ แต่เมื่อ Select ข้อมูลด้วยคำสั่งดังนี้
$sql="select * from tb_member , tb_useronline , tb_useroutline where (tb_member.username=tb_useronline.user_online) and (tb_member.username=tb_useroutline.user_outline) and (tb_useronline.user_online=tb_useroutline.user_outline)and (start_date ='$start_date') group by start_time order by start_date ";
ข้อมูลที่ได้มา คือ Code,Name,LoginDate,LoginTime,LogoutTime
ปัญหาคือหนึ่ง Record เวลาLogin นั้น ตรงขึ้นครบทุกคนแต่เวลา Logout นั้นจะโชว์ข้อมูลครั้งแรกเท่านั้น ไม่ว่าจะLogin กี่ครั้ง Logout กี่ครั้ง รบกวนสอบถามด้วยค่ะว่าควรจะแก้โค้ด Select ยังไง
ออกแบบ ตางรางไว้ ยังไง ล่ะครับ
แล้ว ข้อมูล ในฐานข้อมูล มีอยู่ หรือยัง
แล้ว ข้อมูล ในฐานข้อมูล มีอยู่ หรือยัง
สร้างไฟล์ pdf online
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ออกแบบไว้อย่างนี้ครับ
อันนี้ tb_member ครับ
id int(11) auto_increment
username varchar(50) utf8_general_ci
password varchar(50) utf8_general_ci
confirm varchar(50) utf8_general_ci
name varchar(27) utf8_general_ci
sex text utf8_general_ci
telephone varchar(50) utf8_general_ci
skill varchar(50) utf8_general_ci
reg_date date 0000-00-00
-----------------------------------------
tb_useronline
idonline int(11) auto_increment
user_online varchar(50) utf8_general_ci
online_time varchar(50) utf8_general_ci
start_date date 0000-00-00
start_time time 00:00:00
-----------------------------------------------
tb_useroutline
outline_id varchar(10) utf8_general_ci
user_outline varchar(50) utf8_general_ci
outline_time varchar(50) utf8_general_ci
out_date date 0000-00-00
out_time time 00:00:00
อันนี้ tb_member ครับ
id int(11) auto_increment
username varchar(50) utf8_general_ci
password varchar(50) utf8_general_ci
confirm varchar(50) utf8_general_ci
name varchar(27) utf8_general_ci
sex text utf8_general_ci
telephone varchar(50) utf8_general_ci
skill varchar(50) utf8_general_ci
reg_date date 0000-00-00
-----------------------------------------
tb_useronline
idonline int(11) auto_increment
user_online varchar(50) utf8_general_ci
online_time varchar(50) utf8_general_ci
start_date date 0000-00-00
start_time time 00:00:00
-----------------------------------------------
tb_useroutline
outline_id varchar(10) utf8_general_ci
user_outline varchar(50) utf8_general_ci
outline_time varchar(50) utf8_general_ci
out_date date 0000-00-00
out_time time 00:00:00
แล้ว ข้อมูล ในฐานข้อมูล มีอยู่ จริงหรือเปล่าครับ
สร้างไฟล์ pdf online
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ลอง ศึกษา บทความนี้ครับ สำหรับ ดึงข้อมูลจากหลาย ตาราง
http://www.mindphp.com/modules.php?name ... cle&sid=82
http://www.mindphp.com/modules.php?name ... cle&sid=82
สร้างไฟล์ pdf online
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ท่องเที่ยว http://www.thailandhotelforums.com/" onclick="window.open(this.href);return false;
สอน php http://www.mindphp.com/" onclick="window.open(this.href);return false;
ผู้ใช้งานขณะนี้
กำลังดูบอร์ดนี้: 208 และ บุคคลทั่วไป 0 ท่าน