Session8

1,114 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,114
On SlideShare
0
From Embeds
0
Number of Embeds
740
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Session8

  1. 1. PHP+MYSQL projetcsoft.biz F F ก ก ก F MySQL F PHP
  2. 2. 1. ก ก username password กF ก F MySQL $dbUname="Enter your MySQL username."; $dbPword="Enter your MySQL Password."; $dbHost="Enter your MySQL sever name."; $dbName="Enter your MySQL sever name."; $link=mysql_connect($dbHost,$dbUname,$dbPword); mysql_select_db($dbName,$link); mysql_query('SET CHARACTER SET utf-8'); mysql_query('SET collation_connection utf8_unicode_ci'); projetcsoft.biz F F ก
  3. 3. 2. F SQL F MySQL $sql = " sql "; $result=mysql_query($sql); mysql_close($link); F ก ก F $result projetcsoft.biz F F ก
  4. 4. 3. F F F ก MySQL ก F 2. ก SQL ˈ F F ( Select ) F F mysql_featch_array() F ก $result $resultArray=mysql_featch_array($result); projetcsoft.biz F F ก
  5. 5. F F $sql = "SELECT name,price FROM product"; $result=mysql_query($sql); mysql_close($link); $resultArray=mysql_featch_array($result);$resultArray=mysql_featch_array($result); echo $resultArray[0]; name echo $resultArray[1]; price echo $resultArray["name"]; name echo $resultArray["price"]; price ก F F ก projetcsoft.biz F F ก
  6. 6. ก F F ก F F ก F product ก ก F ก F ก F F loop while F F $resultArray=mysql_featch_array($result);$resultArray=mysql_featch_array($result); while($resultArray=mysql_featch_array($result)) { echo $resultArray["name"]; echo $resultArray["price"]; } F ก F F ก product F projetcsoft.biz F F ก
  7. 7. ก F MySQL F ˈ Function ก ก ก F F Function function runSqlQuery($sql){ $dbUname="Enter your MySQL username.";$dbUname="Enter your MySQL username."; $dbPword="Enter your MySQL Password."; $dbHost="Enter your MySQL sever name."; $dbName="Enter your MySQL sever name."; $link=mysql_connect($dbHost,$dbUname,$dbPword); projetcsoft.biz F F ก
  8. 8. mysql_select_db($dbName,$link); mysql_query('SET CHARACTER SET utf-8'); mysql_query('SET collation_connection utf8_unicode_ci'); ก F MySQL F ˈ Function $result=mysql_query($sql); mysql_close($link); return $result; } projetcsoft.biz F F ก
  9. 9. ก function F กF code F F F ก F $sql = "SELECT name,price FROM product"; $result=runSqlQuery($sql); ก F MySQL F ˈ Function $result=runSqlQuery($sql); while($resultArray=mysql_featch_array($result)) { echo $resultArray["name"]; echo $resultArray["price"]; } projetcsoft.biz F F ก
  10. 10. ก F F ก MySQL Tag Table <table> <tr> <td> F </td> <td> </td> </tr></tr> <?PHP $sql = "SELECT name,price FROM product"; $result=runSqlQuery($sql); while($resultArray=mysql_featch_array($result)) { ?> projetcsoft.biz F F ก
  11. 11. <tr> <td> <?PHP echo $resultArray["name"]; ?> </td> <td> ก F F ก MySQL Tag Table <td> <?PHP echo $resultArray["price"]; ?> </td> </tr> <?PHP } ?> projetcsoft.biz F F ก
  12. 12. <select name="select_product" > <?PHP $sql = "SELECT id,name FROM product"; $result=runSqlQuery($sql); while($resultArray=mysql_featch_array($result)) { ?> ก F F ก MySQL Tag Select { ?> <option value="<?PHP echo $resultArray["id"]; ?>" > <?PHP echo $resultArray["name"]; ?> </option> <?PHP } ?> F F F F ˈ projetcsoft.biz F F ก

×