Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ



 

รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ

 



Topic : 075963



โพสกระทู้ ( 16 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<?php
	class MyClass{
		public function selQuery($sqlTxt){
			if(preg_match('/SELECT/', strtoupper($sqlTxt))){
				$result = mysql_query($sqlTxt);
				$num = mysql_num_rows($result);
				if($num > 0){
					$arrRec = array();
					while($rs = mysql_fetch_assoc($result)){
						array_push($arrRec,$rs);
					}
					return $arrRec;
				}else{
					echo null;
				}
			}else{
				echo null;
			}
		}

		public function query($sql){
			if(@mysql_query($sql))
				return true;
			else
				return false;
		}
		
		public function chkUniqData($tablename,$field,$data){
			$result = mysql_query("Select $field From $tablename Where $field = '$data'");
			$num = mysql_num_rows($result);
			if($num >= 1)
				return false;
			else
				return true;
		}

		public function random_id($len){
			srand((double)microtime()*10000000);
			$chars = "0123456789";
			$ret_str = "";
			$count = 0;
			$chars2 = "";
			while($count<strlen($chars)){
				for($i=0;$i<$len;$i++){
					$chars2 .= $chars[$count];
				}
				$count++;
			}
			$num = strlen($chars2);
			for($i = 0; $i < $len; $i++)
				{
					$ret_str.= $chars2[rand()%$num];
					$ret_str.=""; 
				}
			return $ret_str; 
		}

		public function getDateFormat($timestamp, $type = "d"){
			$d = date("d", $timestamp);
			$m = date("m", $timestamp);
			$y = date("Y", $timestamp)+543;
			$h = date("H", $timestamp);
			$i = date("i", $timestamp);
			$s = date("s", $timestamp);
			$thai_m = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม",
				"กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
			if($type == "d"){
				return $d." ".$thai_m[$m-1]." ".$y;
			}else if($type == "dt"){
				return $d." ".$thai_m[$m-1]." ".$y.", เวลา ".$h.":".$i."น.";
			}
		}

		public function uploadPhoto($arrFile,$name,$dirnm,$limit=0,$option='w'){
			$array_last=explode(".", $arrFile['name']);
			$c=count($array_last)-1;
			$filename=strtolower($array_last[$c]);
			$photo_name = $name.'.'.$filename;
			$chk=false;
			$arrAuthorList=array('jpg','jpeg','gif','png');
			foreach($arrAuthorList as $key){
				if($key==$filename){
					$chk=true;
					break;
				}
			}
			if($chk){
				copy($arrFile['tmp_name'], $dirnm.$photo_name);
				$images = $dirnm.$photo_name;
				$img_size=GetimageSize($images);
				if($option=='w' AND $limit>0){
					if($img_size[0]>$limit){
						$img_width=$limit;
						$img_height=round($img_width*$img_size[1]/$img_size[0]);
					}else{
						$img_width=$img_size[0];
						$img_height=$img_size[1];
					}
				}else if($option=='h' AND $limit>0){
					if($img_size[1]>$limit){
						$img_height=$limit;
						$img_width=round($img_height*$img_size[0]/$img_size[1]);
					}else{
						$img_width=$img_size[0];
						$img_height=$img_size[1];
					}
				}else{
					$img_width=$img_size[0];
					$img_height=$img_size[1];
				}

				if($filename=="jpg" or $filename=="jpeg"){
					$newImg=ImageCreateFromJPEG($images);
					$newX=ImagesX($newImg);
					$newY=ImagesY($newImg);
					$images_fin=ImageCreateTrueColor($img_width, $img_height);
					ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
					ImageJPEG($images_fin, $dirnm.$photo_name);
				}else if($filename=="gif"){
					$newImg=ImageCreateFromGIF($images);
					$newX=ImagesX($newImg);
					$newY=ImagesY($newImg);
					$images_fin=ImageCreateTrueColor($img_width, $img_height);
					ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
					ImageGIF($images_fin, $dirnm.$photo_name);
				}else if($filename=="png"){
					$newImg=ImageCreateFromPNG($images);
					$newX=ImagesX($newImg);
					$newY=ImagesY($newImg);
					$images_fin=ImageCreateTrueColor($img_width, $img_height);
					ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
					ImagePNG($images_fin, $dirnm.$photo_name);
				}

				ImageDestroy($newImg);
				ImageDestroy($images_fin);

				unlink($arrFile['tmp_name']);
				return $photo_name;
			}else{
				return null;
			}
		}

		public function randomNum($num){
			srand((double)microtime()*10000000);
			$n = rand()%$num;
			return $n;
		}

		public function randNonUniqe($num){
			srand((double)microtime()*10000000);
			$a = array();
			while (count($a) < $num) {
			  $n = rand()%$num;
			  if (!in_array($n, $a)) array_push($a,$n);
			}
			return $a;
		}

		public function getItemsFromCart($cart){
			if (isset($cart)) { 
				$items = explode(',',$cart); //ใช้คอมม่าเป็นตัวแยกข้อมูล
				$contents = array(); 
				foreach ($items as $item) {    
					$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;   //นำค่าที่ได้มาเก็บในaray
				}
				return $contents;
			}else{
				return "";
			}
		}
	}
?>




Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-22 16:51:27 By : hikarujun View : 803 Reply : 2
 

 

No. 1



โพสกระทู้ ( 3,844 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

จับใส่ tag php หน่อยก็ดีน่ะครับ ดูยากจัง
Code (PHP)
?php
class MyClass{
public function selQuery($sqlTxt){
if(preg_match('/SELECT/', strtoupper($sqlTxt))){
$result = mysql_query($sqlTxt);
$num = mysql_num_rows($result);
if($num > 0){
$arrRec = array();
while($rs = mysql_fetch_assoc($result)){
array_push($arrRec,$rs);
}
return $arrRec;
}else{
echo null;
}
}else{
echo null;
}
}

public function query($sql){
if(@mysql_query($sql))
return true;
else
return false;
}

public function chkUniqData($tablename,$field,$data){
$result = mysql_query("Select $field From $tablename Where $field = '$data'");
$num = mysql_num_rows($result);
if($num >= 1)
return false;
else
return true;
}

public function random_id($len){
srand((double)microtime()*10000000);
$chars = "0123456789";
$ret_str = "";
$count = 0;
$chars2 = "";
while($count<strlen($chars)){
for($i=0;$i<$len;$i++){
$chars2 .= $chars[$count];
}
$count++;
}
$num = strlen($chars2);
for($i = 0; $i < $len; $i++)
{
$ret_str.= $chars2[rand()%$num];
$ret_str.=""; 
}
return $ret_str; 
}

public function getDateFormat($timestamp, $type = "d"){
$d = date("d", $timestamp);
$m = date("m", $timestamp);
$y = date("Y", $timestamp)+543;
$h = date("H", $timestamp);
$i = date("i", $timestamp);
$s = date("s", $timestamp);
$thai_m = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม",
"กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
if($type == "d"){
return $d." ".$thai_m[$m-1]." ".$y;
}else if($type == "dt"){
return $d." ".$thai_m[$m-1]." ".$y.", เวลา ".$h.":".$i."น.";
}
}

public function uploadPhoto($arrFile,$name,$dirnm,$limit=0,$option='w'){
$array_last=explode(".", $arrFile['name']);
$c=count($array_last)-1;
$filename=strtolower($array_last[$c]);
$photo_name = $name.'.'.$filename;
$chk=false;
$arrAuthorList=array('jpg','jpeg','gif','png');
foreach($arrAuthorList as $key){
if($key==$filename){
$chk=true;
break;
}
}
if($chk){
copy($arrFile['tmp_name'], $dirnm.$photo_name);
$images = $dirnm.$photo_name;
$img_size=GetimageSize($images);
if($option=='w' AND $limit>0){
if($img_size[0]>$limit){
$img_width=$limit;
$img_height=round($img_width*$img_size[1]/$img_size[0]);
}else{
$img_width=$img_size[0];
$img_height=$img_size[1];
}
}else if($option=='h' AND $limit>0){
if($img_size[1]>$limit){
$img_height=$limit;
$img_width=round($img_height*$img_size[0]/$img_size[1]);
}else{
$img_width=$img_size[0];
$img_height=$img_size[1];
}
}else{
$img_width=$img_size[0];
$img_height=$img_size[1];
}

if($filename=="jpg" or $filename=="jpeg"){
$newImg=ImageCreateFromJPEG($images);
$newX=ImagesX($newImg);
$newY=ImagesY($newImg);
$images_fin=ImageCreateTrueColor($img_width, $img_height);
ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
ImageJPEG($images_fin, $dirnm.$photo_name);
}else if($filename=="gif"){
$newImg=ImageCreateFromGIF($images);
$newX=ImagesX($newImg);
$newY=ImagesY($newImg);
$images_fin=ImageCreateTrueColor($img_width, $img_height);
ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
ImageGIF($images_fin, $dirnm.$photo_name);
}else if($filename=="png"){
$newImg=ImageCreateFromPNG($images);
$newX=ImagesX($newImg);
$newY=ImagesY($newImg);
$images_fin=ImageCreateTrueColor($img_width, $img_height);
ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY); 
ImagePNG($images_fin, $dirnm.$photo_name);
}

ImageDestroy($newImg);
ImageDestroy($images_fin);

unlink($arrFile['tmp_name']);
return $photo_name;
}else{
return null;
}
}

public function randomNum($num){
srand((double)microtime()*10000000);
$n = rand()%$num;
return $n;
}

public function randNonUniqe($num){
srand((double)microtime()*10000000);
$a = array();
while (count($a) < $num) {
$n = rand()%$num;
if (!in_array($n, $a)) array_push($a,$n);
}
return $a;
}

public function getItemsFromCart($cart){
if (isset($cart)) { 
$items = explode(',',$cart); //ใช้คอมม่าเป็นตัวแยกข้อมูล
$contents = array(); 
foreach ($items as $item) { 
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; //นำค่าที่ได้มาเก็บในaray
}
return $contents;
}else{
return "";
}
}
}
?>







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 16:54:30 By : mangkunzo
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ยาวขนาดนี้จะให้อธิบายหมดเหรอครับ เอาเป็นว่าถามจุด ๆ แล้วกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 20:43:01 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่