Try   HackMD

使用Dreamweaver設定PHP&MYSQL開發環境

tags: PHP MYSQL

(使用 Dreamweaver 與 XAMPP 設定環境)

  1. 確認電腦安裝與設置好XAMPP開啟
  2. Dreamweaver設定開發環境,網站>新增網站(專案)
  3. 增一個Dreamweaver的PHP檔案

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

路徑指定C:\xampp\htdocs\phptest\ (此為預設路徑)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

伺服器資料夾要指向同一個位置(C:\xampp\htdocs\phptest)
網址指定到http://localhost/phptest/

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

進階>伺服器模式要設定為 PHP MySQL

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

新增一個Dreamweaver的PHP檔案


PHP的起始與結束

PHP變數

  • 只可使用英文字母與底線_
  • 大小寫字母視為不同變數(
    a
    A是不同哦)

註解方式

//單行註解
/多行註解/
變數放在" "內程式碼也會執行
變數放在' '內是純文字


PHP題目練習

<?php
$name="周杰倫";
$price=400;
$goods="衣服";
cho $name ."花了" .$price ."元,買了一件".$goods
?>

也可以寫成
echo "$name 花了$price 元,買了一件$goods 。"

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


格式化字串sprintf

http://www.php.net/函式名稱 (可查詢函式內容)

公式:[ sprintf(字串格式,

1,來源值2,$來源值3) ]

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

/周杰倫花了400元,買了一件衣服/

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

變數 代表意思
%s 字串
%d 整數
%b 二進制
%c 字元
%f 浮點數
%x 小寫英文字母
%X 大寫英文字母

流程控制

小提醒:先把判斷句內的括號都打好,才不容易漏掉
單純判斷式(條件句)

  • ifelse
  • switch

重複迴圈

  • for
  • while
  • dowhile
符號 意思
|| or
&& and
! not
!= 不等於
== 等於
> 大於
>= 大於等於
< 小於
<= 小於等於

變數函數都可以使用加減乘除符號

+  $a+7
-  $a-5
*  $a*3
/  $a/4
%  (取餘數) 50%71 ; 50%122

練習題:ifelse練習+sprintf

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

更簡單的寫法↓

<?php
	$A=16;
	if($A%2==1){
		echo $A."是奇數";
	}else{
		echo $A."是偶數";
	}
	
echo "<br>";	
	
	$B=8;
	if($B%2==0){
		echo $B."是偶數";
	}else{
		echo $B."是奇數";
	}	
?>

常犯錯誤

<?php $weather="sun" if($weather == "rain"){ echo"下雨了"; } ?>

等號要用==兩個才是PHP裡面的等於