20 กรกฎาคม 2553

ลบ SESSION แบบเกลี้ยง

session_name('newname');
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    $params = session_get_cookie_params();
    setcookie(session_name(), '', time() - 42000,
        $params["path"], $params["domain"],
        $params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();
?> 

10 กรกฎาคม 2553

คำสั่งที่ใช้ในการเปลี่ยนรูปแบบวันที่ ใน SQL

เมื่อเราเก็บวันที่ในรูปแบบ 10-05-2010 หากเราทำการค้นหา โปรแกรมจะมองเห็นแค่ 2 ตัวแรก

ซึ่งเราต้องทำให้มันอยู่ในรูปแบบของฟอร์แมต เครื่อง คือ 2010-05-10 เสียก่อน ถึงจะทำการค้นหาได้ถูกต้อง

คำสั่งข้างล่างจะทำการเปลี่ยนรูปแบบวันที่ก่อนนำไปค้นหา

จาก text_date_field = 10-05-2010

CONCAT(SUBSTRING(`text_date_field` ,7 ,4) ,'-' ,SUBSTRING(`text_date_field` ,4 ,2) ,'-' ,SUBSTRING(`text_date_field` ,1 ,2))

เมื่อแปลงแล้วจะได้ 2010-05-10