SlideShare a Scribd company logo
1 of 34
PHP Programming
o Simple function in PHP
o Connect to MySQL
Date and Time Functions
การใช้ฟังก์ชั่น date();
 ฟังก์ชั้นนี้เอาไว้อานค่าของวัน เดือน ปีและเวลา
                    ่
 ปัจจุบัน
เช่น รูปแบบของวันเดือนปี date("Y-m-d");
จะหมายถึงสตริงค์ที่กำาหนดรูปแบบ ของการ
  แสดงผลวันที่
ผลลัพธ์ที่ได้จากตัวอย่างข้างต้นนี้ คือ
  2006-08-24
โดย Y =ปี ,m=เดือน ,d = วันที่
Date and Time Functions
<?php
 $Today = date("d/m/Y");
                     14/07/2007
 echo $Today;
?>
$yearfull = date("Y")+543;   // ปี พ.ศ. แบบเต็ม
$yearsmall= date("y")+43;    // ปี พ.ศ. แบบย่อ
รูปแบบ                                         ความหมาย
      d         วันที่ เช่น 24
     m          เดือน เช่น 08
      y         ปี ค.ศ. แบบย่อ เช่น 06
      Y         ปี ค.ศ. แบบเต็ม เช่น 2006
  Y+543         ปี ค.ศ ปัจจุบันแบบเต็ม+543 จะเท่ากับ ปี พ.ศ ปัจจุบัน เช่น 2549
   y+43         ปี ค.ศ ปัจจุบันแบบย่อ+43 จะเท่ากับ ปี พ.ศ ปัจจุบัน เช่น 49
     M          ชื่อเดือนแบบย่อ เช่น Mar
      F         ชื่อเดือนแบบเต็ม เช่น March
   l (แอล)      ชื่อวันแบบเต็ม เช่น Thursday

      H         แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12"
      i         แสดงเวลานาที "00" ถึง "59"
      s         แสดงเวลาวินาที "00" ถึง "59"
      h         แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12"
      a         จะแสดงผลเป็น a.m. และ p.m. แบบตัวพิมพ์เล็ก
     A          จะแสดงผลเป็น A.M. และ P.M. แบบตัวพิมพ์ใหญ่
   *หมายเหตุ A.M.(ante meridium) คือ เอาไว้ใช้ในการบอกเวลาตังแต่เที่ยงคืนถึงเที่ยงวัน และ
                                                                ้
P.M.( past meridium) ใช้ในการบอกเวลาตังแต่เที่ยงวันถึงเที่ยงคืน
                                      ้
a แสดงคำาว่า am หรือ pm ในรูปแบบตัวพิมพ์เล็ก
A แสดงคำาว่า AM หรือ PM ในรูปแบบตัวพิมพ์ใหญ่
d แสดงวันที่แบบเลข 2 หลัก คือ "01" ถึง "31"
D แสดงชื่อวันภาษาอังกฤษแบบย่อ เช่น "Sun" , "Fri" เป็นต้น
F แสดงชื่อเดือนภาษาอังกฤษเช่น "January"
h แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12"
H แสดงเวลาชั่วโมงแบบ 2 หลัก "00" ถึง "23"
g แสดงเวลาชั่วโมงแบบไม่มีเลข 0 นำาหน้า "1" ถึง "12"
G แสดงเวลาชั่วโมงแบบไม่มีเลข 0 นำาหน้า "0" ถึง "23"
i แสดงเวลานาที "00" ถึง "59"
j แสดงวันที่แบบไม่มีเลข 0 นำาหน้า "1" ถึง "31"
l แสดงชื่อวันภาษาอังกฤษแบบเต็ม เช่น "Monday"
L แสดงค่าทางตรรกะ คือ มีคา 0 หรือ 1 ในปีที่เป็นอธิกมาส
                              ่
m แสดงเดือนแบบตัวเลขมีเลข 0 นำาหน้า "01" ถึง "12"
n แสดงชื่อเดือนภาษาอังกฤษแบบย่อ 3 ตัวอักษร เช่น "Feb"
s แสดงเวลาวินาที "00" ถึง "59"
S แสดงส่วนต่อท้ายของวันที่ เช่น "th", "nd"
t แสดงจำานวนวันใน 1 เดือน
w แสดงตัวเลขของวันใน 1 สัปดาห์ เช่น "0" = Sunday ถึง "6" = Saturday
Y แสดงปี ค.ศ. ตัวเลข 4 หลัก เช่น “2006"
y แสดงปี ค.ศ. ตัวเลข 2 หลัก เช่น “06"
z แสดงลำาดับวันใน 1 ปี คือตังแต่ "0" ถึง "365"
                            ้
Date and Time Functions
mktime()
ใช้ให้การกำาหนดหรือสร้างวันเวลาที่เรา
 ต้องการ
mktime (hour, minute, second ,
 month, day ,year)
date() and mktime()
การใช้งาน Function include()

o Include เป็นการเรียกใช้งานไฟล์อื่น เพือ
                                        ่
  ทำางานร่วมกับ
ไฟล์ที่กำาลังทำางานอยู่
      รูปแบบ include("files-name")
Example include()
table.php
Example include()
testinclude.php
Function ในกลุ่มเดียวกันกับ
          include()
oinclude()
oinclude_once()
orequire()
orequire_once()
oget_included_files()
oget_required_files()
Function ที่ใช้กันบ่อยในการติดต่อ
            กับ mysql
mysql_connect()
ใช้ในการเชื่อมต่อกับฐานข้อมูล
mysql_select_db

o ใช้ในการเลือกฐานข้อมูลที่จะใช้งาน
mysql_query
o ใช้ในการ execute คำาสัง command SQL




$result เป็นตัวแปลเก็บผลจากการ execute
command sql
$result เป็นตัวแปลในรูปแบบ ตัวแปล resource
การดึงค่าออกจากตัวแปล $result
มีหลาย function ที่ในการดึงเอาข้อมูลจากตัว
  แปล $result มาแสดง
ตัวแปล $result เป็นตัวแปลในรูปแบบ ตัว
  แปล resource
o mysql_fetch_array()
o mysql_fetch_object()
o mysql_result()           //***** เป็น
  ทีนิยมและใช้กันมาก
    ่
การนำาจำานวนในตัวแปล resource
mysql_fetch_array()
เป็นการดึงเอาค่าตัวแปล resource มาอยู่
  ในรูปแบบ array
เพื่อทำาการแสดงผม โดยมีการดึงให้อยู่ใน
  รูปแบบ 3 แบบคือ

o mysql_fetch_array() with
  MYSQL_NUM
  // index ใน array เป็น number
o mysql_fetch_array() with
  MYSQL_ASSOC
  // index ใน array เป็น string
mysql_fetch_array()
with MYSQL_NUM
mysql_fetch_array() with
   MYSQL_ASSOC
mysql_fetch_array() with
   MYSQL_BOTH
mysql_fetch_object()
เป็นการดึงข้อมูลจากตัวแปล resource ให้อยุ่
  ในรูปตัวแปล object
mysql_result()
เป็นการดึงข้อมูลโดยตรงจากตัวแปล
   resource และต้องใช้งาน
รวมกับ function mysql_num_rows()
   ซึงใช้นับจำานวน row ที่
     ่
Query ได้
รูปแบบ คำาสัง ่
mysql_result()
มาทำาตัวอย่าง
พร้อมๆ กันเลย
Step 1 : create data base
Step 2:Create table
Create PHP File
list.php
Work shop 20%

oPhoto gallery
oShop product
 - Add , edit , update or delete
Php + Mysql + Hhtm + Css

More Related Content

More from Jenchoke Tachagomain

Introduction to On-line Documemt Lect05 Web Process
Introduction to On-line Documemt  Lect05 Web ProcessIntroduction to On-line Documemt  Lect05 Web Process
Introduction to On-line Documemt Lect05 Web ProcessJenchoke Tachagomain
 
Introduction to On-line Documemt Lect03 E Commerce
Introduction to On-line Documemt  Lect03 E CommerceIntroduction to On-line Documemt  Lect03 E Commerce
Introduction to On-line Documemt Lect03 E CommerceJenchoke Tachagomain
 
Introduction to On-line Documemt Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02Jenchoke Tachagomain
 
Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Jenchoke Tachagomain
 
Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Jenchoke Tachagomain
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09Jenchoke Tachagomain
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08Jenchoke Tachagomain
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04Jenchoke Tachagomain
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03Jenchoke Tachagomain
 

More from Jenchoke Tachagomain (20)

Digital Transformation
Digital TransformationDigital Transformation
Digital Transformation
 
Android programming
Android programmingAndroid programming
Android programming
 
Android architecture
Android architectureAndroid architecture
Android architecture
 
Lect 08 Css
Lect 08 CssLect 08 Css
Lect 08 Css
 
Lect07 Page Design
Lect07 Page DesignLect07 Page Design
Lect07 Page Design
 
Lect06 Web Design
Lect06 Web DesignLect06 Web Design
Lect06 Web Design
 
Introduction to On-line Documemt Lect05 Web Process
Introduction to On-line Documemt  Lect05 Web ProcessIntroduction to On-line Documemt  Lect05 Web Process
Introduction to On-line Documemt Lect05 Web Process
 
Introduction to On-line Documemt Lect03 E Commerce
Introduction to On-line Documemt  Lect03 E CommerceIntroduction to On-line Documemt  Lect03 E Commerce
Introduction to On-line Documemt Lect03 E Commerce
 
Introduction to On-line Documemt Lec02
Introduction to On-line Documemt  Lec02Introduction to On-line Documemt  Lec02
Introduction to On-line Documemt Lec02
 
Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4Introduction to On-line Documemt Lab 4
Introduction to On-line Documemt Lab 4
 
Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3Introduction to On-line Documemt Lab 3
Introduction to On-line Documemt Lab 3
 
Lab 2 For Css
Lab 2 For CssLab 2 For Css
Lab 2 For Css
 
Rss
RssRss
Rss
 
Digital Content Business
Digital Content BusinessDigital Content Business
Digital Content Business
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 09
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 08
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 04
 
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03
การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 03
 
Communication Concept
Communication ConceptCommunication Concept
Communication Concept
 
Communication Concept 3
Communication Concept 3Communication Concept 3
Communication Concept 3
 

การพัฒนาเอกสารออนไลน์ขั้นสูง Lect 07

  • 1. PHP Programming o Simple function in PHP o Connect to MySQL
  • 2. Date and Time Functions การใช้ฟังก์ชั่น date(); ฟังก์ชั้นนี้เอาไว้อานค่าของวัน เดือน ปีและเวลา ่ ปัจจุบัน เช่น รูปแบบของวันเดือนปี date("Y-m-d"); จะหมายถึงสตริงค์ที่กำาหนดรูปแบบ ของการ แสดงผลวันที่ ผลลัพธ์ที่ได้จากตัวอย่างข้างต้นนี้ คือ 2006-08-24 โดย Y =ปี ,m=เดือน ,d = วันที่
  • 3. Date and Time Functions <?php $Today = date("d/m/Y"); 14/07/2007 echo $Today; ?> $yearfull = date("Y")+543; // ปี พ.ศ. แบบเต็ม $yearsmall= date("y")+43; // ปี พ.ศ. แบบย่อ
  • 4. รูปแบบ ความหมาย d วันที่ เช่น 24 m เดือน เช่น 08 y ปี ค.ศ. แบบย่อ เช่น 06 Y ปี ค.ศ. แบบเต็ม เช่น 2006 Y+543 ปี ค.ศ ปัจจุบันแบบเต็ม+543 จะเท่ากับ ปี พ.ศ ปัจจุบัน เช่น 2549 y+43 ปี ค.ศ ปัจจุบันแบบย่อ+43 จะเท่ากับ ปี พ.ศ ปัจจุบัน เช่น 49 M ชื่อเดือนแบบย่อ เช่น Mar F ชื่อเดือนแบบเต็ม เช่น March l (แอล) ชื่อวันแบบเต็ม เช่น Thursday H แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12" i แสดงเวลานาที "00" ถึง "59" s แสดงเวลาวินาที "00" ถึง "59" h แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12" a จะแสดงผลเป็น a.m. และ p.m. แบบตัวพิมพ์เล็ก A จะแสดงผลเป็น A.M. และ P.M. แบบตัวพิมพ์ใหญ่ *หมายเหตุ A.M.(ante meridium) คือ เอาไว้ใช้ในการบอกเวลาตังแต่เที่ยงคืนถึงเที่ยงวัน และ ้ P.M.( past meridium) ใช้ในการบอกเวลาตังแต่เที่ยงวันถึงเที่ยงคืน ้
  • 5. a แสดงคำาว่า am หรือ pm ในรูปแบบตัวพิมพ์เล็ก A แสดงคำาว่า AM หรือ PM ในรูปแบบตัวพิมพ์ใหญ่ d แสดงวันที่แบบเลข 2 หลัก คือ "01" ถึง "31" D แสดงชื่อวันภาษาอังกฤษแบบย่อ เช่น "Sun" , "Fri" เป็นต้น F แสดงชื่อเดือนภาษาอังกฤษเช่น "January" h แสดงเวลาชั่วโมงแบบ 2 หลัก "01" ถึง "12" H แสดงเวลาชั่วโมงแบบ 2 หลัก "00" ถึง "23" g แสดงเวลาชั่วโมงแบบไม่มีเลข 0 นำาหน้า "1" ถึง "12" G แสดงเวลาชั่วโมงแบบไม่มีเลข 0 นำาหน้า "0" ถึง "23" i แสดงเวลานาที "00" ถึง "59" j แสดงวันที่แบบไม่มีเลข 0 นำาหน้า "1" ถึง "31" l แสดงชื่อวันภาษาอังกฤษแบบเต็ม เช่น "Monday" L แสดงค่าทางตรรกะ คือ มีคา 0 หรือ 1 ในปีที่เป็นอธิกมาส ่ m แสดงเดือนแบบตัวเลขมีเลข 0 นำาหน้า "01" ถึง "12" n แสดงชื่อเดือนภาษาอังกฤษแบบย่อ 3 ตัวอักษร เช่น "Feb" s แสดงเวลาวินาที "00" ถึง "59" S แสดงส่วนต่อท้ายของวันที่ เช่น "th", "nd" t แสดงจำานวนวันใน 1 เดือน w แสดงตัวเลขของวันใน 1 สัปดาห์ เช่น "0" = Sunday ถึง "6" = Saturday Y แสดงปี ค.ศ. ตัวเลข 4 หลัก เช่น “2006" y แสดงปี ค.ศ. ตัวเลข 2 หลัก เช่น “06" z แสดงลำาดับวันใน 1 ปี คือตังแต่ "0" ถึง "365" ้
  • 6. Date and Time Functions
  • 9. การใช้งาน Function include() o Include เป็นการเรียกใช้งานไฟล์อื่น เพือ ่ ทำางานร่วมกับ ไฟล์ที่กำาลังทำางานอยู่ รูปแบบ include("files-name")
  • 12. Function ในกลุ่มเดียวกันกับ include() oinclude() oinclude_once() orequire() orequire_once() oget_included_files() oget_required_files()
  • 16. mysql_query o ใช้ในการ execute คำาสัง command SQL $result เป็นตัวแปลเก็บผลจากการ execute command sql $result เป็นตัวแปลในรูปแบบ ตัวแปล resource
  • 17. การดึงค่าออกจากตัวแปล $result มีหลาย function ที่ในการดึงเอาข้อมูลจากตัว แปล $result มาแสดง ตัวแปล $result เป็นตัวแปลในรูปแบบ ตัว แปล resource o mysql_fetch_array() o mysql_fetch_object() o mysql_result() //***** เป็น ทีนิยมและใช้กันมาก ่ การนำาจำานวนในตัวแปล resource
  • 18. mysql_fetch_array() เป็นการดึงเอาค่าตัวแปล resource มาอยู่ ในรูปแบบ array เพื่อทำาการแสดงผม โดยมีการดึงให้อยู่ใน รูปแบบ 3 แบบคือ o mysql_fetch_array() with MYSQL_NUM // index ใน array เป็น number o mysql_fetch_array() with MYSQL_ASSOC // index ใน array เป็น string
  • 23. mysql_result() เป็นการดึงข้อมูลโดยตรงจากตัวแปล resource และต้องใช้งาน รวมกับ function mysql_num_rows() ซึงใช้นับจำานวน row ที่ ่ Query ได้ รูปแบบ คำาสัง ่
  • 26. Step 1 : create data base
  • 29.
  • 30.
  • 31.
  • 33.
  • 34. Work shop 20% oPhoto gallery oShop product - Add , edit , update or delete Php + Mysql + Hhtm + Css