<?php date_default_timezone_set('Asia/Bangkok');//เซตโซนเวลาให้เป็นเวลาในไทย mysql_connect("localhost","root","1234"); mysql_select_db("e-auction"); $sql="select*from product "; $sqlquery = mysql_query($sql); while($result = mysql_fetch_array($sqlquery)){ $toDay = strtotime($result['end_time']); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=tis620" /> <script type="text/javascript" src="easyslider1.7/js/jquery.js"></script> <title>สอนเขียนโค๊ดนับเวลาถอยหลัง</title> <script type="text/javascript"> function countDown(times){//times ค่าเวลาต้องเป็น timeslamp เท่านั้น //ตัวแปร toDay รับค่าวันเวลาปัจจุบันแบบ timestamp var toDay=Math.round(new Date().getTime()/1000); //ค่าของ timestamp โดยหาร 1000 จะได้ค่าเป็นแบบ second //หาวันเวลาที่เหลือ อ้างอิงจาก http://www.thai-access.com/topic_post.asp?CategoryID=1&TopicID=2431 var difTime=times-toDay; var day=0,hours=0,minutes=0,seconds=0; if(difTime>0){//หากเวลายังไม่หมด day=Math.floor(difTime/84600);//หาค่าวัน hours=Math.floor((difTime/3600))%24;//หาชั่วโมง minutes=Math.floor(difTime/60)%60;//หานาที seconds=Math.floor(difTime)%60;//หาวินาที countDown_onLoad();//ทำงานต่อ }else{//ถ้าหมดเวลา alert('หมดเวลา'); //สามารถเขียนcodeเพิ่มเติมในส่วนนี้ได้ เช่น ถ้าหมดเวลาแล้วให้redirectไปหน้าindex.php ให้ใช้คำสั่ง window.location='index.php'; } $('.show').html(day+' วัน '+hours+' ชั่วโมง '+minutes+' นาที '+seconds+' วินาที '); } function countDown_onLoad(){ //แทรกcode PHP เข้าไปใน Javascript ได้เลย setTimeout("countDown(<?=$toDay ?>);",1000);//1000=1วินาที } $(document).ready(function() { countDown_onLoad(); }); </script> </head> <body> <div class="show"></div><!--แสดงผลลัพธุ์ตรงนี้--> </body> </html> <? } ?>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง