博客來網路書店查詢

書名

博客來網路書店查詢

星期一, 11月 22, 2010

PHP&MySQL--12 2010年11月課程講義預覽

PHP&MySQL--12
一、 沒有對應的方法與權限會如何呈現呢
1. 基本樣式


〈html〉〈head〉
〈meta http-equiv="content-type" content="text/html; charset=utf-8" /〉
〈title〉沒有對應的方法與權限會如何呈現呢〈/title〉〈/head〉
〈body〉
class cbox {
private $lenght1;
private $breadth1;
private $height1;
function getdata( ) {
return $this-〉breadth1*$this-〉height1*$this-〉lenght1;
}
}
$box1 = new cbox;
$box1-〉titlename="php";
echo $box1-〉titlename;
$box1-〉test2(123);〈/body〉〈/html〉



2. 處理方式【另存新檔後增加或修改內容】

function __get($var) {
echo "沒有對應的屬性可處理,若無此函數該屬性會自動產生:".$var."〈br〉"; }
function __set($a,$b) {
echo "沒有對應的屬性可接收,若無此函數該屬性會自動產生:".$a."〈br〉";
echo "第二個參數:".$b."〈br〉"; }
function __call($a,$b) {
echo "沒有對應的函數可處理,若無此函數會產生錯誤訊息:".$a."〈br〉";
echo "第二個參數:".$b."〈br〉"; }




3. 權限不合的處理方式?【另存新檔後增加或修改內容】

$box1 = new cbox;
$box1-〉lenght1="php";
echo $box1-〉lenght1;
$box1-〉test2(123);




二、 物件複製是否有錯?


〈html〉〈head〉
〈meta http-equiv="content-type" content="text/html; charset=utf-8" /〉
〈title〉物件複製是否有錯〈/title〉〈/head〉〈body〉
class cbox {
private $lenght1;
private $breadth1;
private $height1;
function __construct($a,$b,$c) {
$this-〉lenght1=$a;
$this-〉breadth1=$b;
$this-〉height1=$c;
}
function setlength1($lenght1)
{ $this-〉lenght1=$lenght1; }
function getlength1( )
{ return $this-〉lenght1; }
function getdata( ) {
return $this-〉breadth1*$this-〉height1*$this-〉lenght1; }
}
$box1 = new cbox(20,20,20);
$box2 = $box1;
$box2-〉setlength1(30);
echo "第1個箱子length1=".$box1-〉getlength1( )."〈br〉";
echo "第2個箱子length1=".$box2-〉getlength1( )."〈br〉";〈/body〉〈/html〉



三、 繼承
1. 基本樣式


〈html〉〈head〉
〈meta http-equiv="content-type" content="text/html; charset=utf-8" /〉
〈title〉繼承〈/title〉〈/head〉〈body〉
class cat extends animal {
function __construct( ) {
echo "產生一隻貓科動物"."〈br〉";
} }
class tiger extends cat{
function __construct( ) {
echo "產生一隻老虎"."〈br〉";
} }
class animal {
function __construct( ) {
echo "產生一隻動物"."〈br〉";
} }
$tiger1 = new tiger;
echo "〈hr〉";
$cat1 = new cat;
echo "〈hr〉";
$animal2 = new animal;
echo "〈hr〉";〈/body〉〈/html〉



2. 子類別執行父類別的建構子


class cat extends animal {
function __construct( ) {
parent::__construct( );//new
echo "產生一隻貓科動物"."〈br〉";
} }



3. 父子類別都有相同的方法

class cat extends animal {
function __construct( ) {
parent::__construct( );//new
echo "產生一隻貓科動物"."〈br〉"; }
function run( )
{ echo "貓科動物跑得快"."〈br〉"; } }
class tiger extends cat{
function __construct( ) {
echo "產生一隻老虎"."〈br〉"; }
function run( )
{ echo "老虎跑得快"."〈br〉"; } }




4. 子類別執行父類別的方法


class tiger extends cat{
function __construct( ) {
echo "產生一隻老虎"."〈br〉"; }
function run( )
{ echo "老虎跑得快"."〈br〉";
return parent::run( ); } }



四、 影像處理:劃框線


$img = ImageCreateFromPNG('img.png');
$color_black = ImageColorAllocate($img, 0, 0, 0);
drawBorder($img, $color_black, 30);
header('Content-type: image/png');
Imagepng($img);
function drawBorder(&$img, &$color, $thickness = 1)
{
$x1 = 0;
$y1 = 0;
$x2 = ImageSX($img) - 1;
$y2 = ImageSY($img) - 1;
for($i = 0; $i 〈 $thickness; $i++)
{
ImageRectangle($img, $x1++, $y1++, $x2--, $y2--, $color_black);
}
}




五、 繪製圖表-1

header("Content-type: image/png");
$arrval = array(12,123,21,32,77,85,166,176,163,121);
$height = 260;
$width = 330;
$im = imagecreate($width,$height);
$white = imagecolorallocate($im,255,255,255);
$gray = imagecolorallocate($im,200,200,200);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
$x = 21;
$y = 11;
$num = 0;
while($x〈=$width && $y〈=$height){
$prcnt = ((($height-50)-($y-1))/($height-60))*100;
imageline($im, 21, $y, $width-10, $y, $gray);
imageline($im, $x, 11, $x, $height-50, $gray);
imagestring($im,2,1,$y-10,$prcnt.'%',$red);
imagestring($im,2,$x-3,$height-40,$num,$red);
$x += 30;
$y += 20;
$num++;
}
$tx = 20;
$ty = 210;
foreach($arrval as $values){
$cx = $tx + 30;
$cy = 200-$values;
imageline($im,$tx,$ty,$cx,$cy,$red);
imagestring($im,5,$cx-3,$cy-13,'.',$red);
$ty = $cy;
$tx = $cx;
}
imageline($im, 20, 11, 20, $height-50, $black);
imageline($im, 20, $height-49, $width-10, $height-49, $black);
imagestring($im,3,10,$height-20,'Line Graph by: Roseindia Technologies',$red);
imagepng($im);




六、 繪製圖表-2


$image = imagecreatetruecolor(300, 300);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred = imagecolorallocate($image, 0x90, 0x00, 0x00);
for ($i = 160; $i 〉 150; $i--) {
imagefilledarc($image, 150, $i, 200, 100, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 200, 100, 45, 75 , $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 200, 100, 75, 360 , $darkred, IMG_ARC_PIE);
}
imagefilledarc($image, 150, 150, 200, 100, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 150, 150, 200, 100, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 150, 150, 200, 100, 75, 360 , $red, IMG_ARC_PIE);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);




七、 繪製圖表與資料庫


include "db.php";
$qt=mysql_query("select * from gd_graph");
header ("Content-type: image/jpg");
$x_gap=40;
$x_max=$x_gap*13;
$y_max=250;
$im = @ImageCreate ($x_max, $y_max) or die ("Cannot Initialize new GD image
stream");
$background_color = ImageColorAllocate ($im, 234, 234, 234);
$text_color = ImageColorAllocate ($im, 233, 14, 91);
$graph_color = ImageColorAllocate ($im,25,25,25);
$x1=0;
$y1=0;
$first_one="yes";
while($nt=mysql_fetch_array($qt)){
$x2=$x1+$x_gap;
$y2=$y_max-$nt[sales];
//ImageString($im,2,$x2,$y2,$nt[month].$nt[sales],$graph_color);
ImageString($im,2,$x2,$y2,$nt[month],$graph_color);
if($first_one=="no"){
imageline ($im,$x1, $y1,$x2,$y2,$text_color);
}
$x1=$x2;
$y1=$y2;
$first_one="no";
}
ImageJPEG ($im);




八、 其他

沒有留言: