sondmk header
การเขียนโปรแกรมด้วยภาษา PHP เบื้้องต้น

PHP : Function > getCbo_Month($cboName,$getPost)

Post by Goborijung at 2021-03-19 10:29:41 | ID: 1021

function getCbo_Month($cboName,$getPost)
		{
			$arrMonth = array(
				'1' 	=> 'January'
				,'2' 	=> 'February'
				,'3' 	=> 'March'
				,'4' 	=> 'April'
				,'5' 	=> 'May'
				,'6' 	=> 'June'
				,'7' 	=> 'July '
				,'8' 	=> 'August'
				,'9' 	=> 'September'
				,'10' => 'October'
				,'11' => 'November'
				,'12' => 'December'
			);
			echo "<select name='".$cboName."' id='".$cboName."' class='form-control'>";
			foreach($arrMonth as $key => $val)
			{
				if($key == @$getPost)
				{
					echo "<option value='".$key."' selected>".$val."</option>";
				}
				else
				{
					echo "<option value='".$key."'>".$val."</option>";
				}
			}
			echo "</select>";
		}

// การใช้งาน

$db->getCbo_Month($cboName,$getPost);

PHP : Function > getDgv($sql,$arrHeader,$arrColCenter)

Post by Goborijung at 2021-03-19 15:51:14 | ID: 1022

// Function

function getDgv($sql, $arrHeader, $arrColCenter) { include 'config.php'; $qry = sqlsrv_query($conn, $sql); if ($qry) { // Create Table Header echo "<div class='table-responsive'><table class='table table-bordered table-striped table-hover'><thead><tr><th>No</th>"; foreach($arrHeader as $val) { echo "<th>".$val. "</th>"; } echo "</tr></thead><tbody>"; $no = 1; //no while ($rs = sqlsrv_fetch_array($qry)) { echo "<tr>"; echo "<td class='text-center'>".$no. "</td>"; foreach($arrHeader as $val) //Loop <td> { if (gettype($rs[$val]) == 'object') { if (in_array($val, $arrColCenter)) { echo "<td class='text-center'>".date_format($rs[$val], 'd/m/Y'). "</td>"; } else { echo "<td>".date_format($rs[$val], 'd/m/Y'). "</td>"; } } else { if (in_array($val, $arrColCenter)) { echo "<td class='text-center'>".$rs[$val]. "</td>"; } else { echo "<td>".$rs[$val]. "</td>"; } } } //end-foreach echo "</tr>"; $no++; } //end-while echo "</tbody>"; echo "<tfoot><tr style='background-color: lightgray;'><td colspan='".(count($arrHeader) + 1). "'> Total : ".number_format(($no - 1)). " Records</td></tr></tfoot>"; echo "</table></div>"; echo "<div style='background-color: lightgray;'>Total : ".number_format(($no - 1)). " Records</div>"; } //end-if-qry sqlsrv_close($conn); } //end-function

// การใช้งาน

$db->getDgv($sql,$arrHeader,$arrColCenter);

PHP : Function > getIssetPost($arrPost, $showVar = false)

Post by Goborijung at 2021-03-19 10:30:45 | ID: 1023

// ตัวอย่าง Function

function getIssetPost($arrPost, $showVar = false) { foreach($arrPost as $val) { $ { $val } = issetPOST($val); } if ($showVar == true) { echo "<div class='container-fluid'><div class='row'><div class='col-sm-12'>"; foreach($arrPost as $val) { echo $val. " : <span class="text-danger">".$ { $val }. "</span> | "; } echo "</div></div></div>"; } }

// การใช้งาน

$ct - > getIssetPost($arrPost, $showVar = false);

// ตัวอย่างการใช้งานจริง

include 'class/mainClass.php'; $db = new dbConn(); $ct = new classTools(); $arrPost = array('txtStartDate', 'txtEndDate', 'txtVendor', 'txtDocumentNo','cboInterfaceType'); foreach($arrPost as $val) { ${ $val } = issetPOST($val); } $ct->getIssetPost($arrPost,true); //Show valPost

PHP : Function > getRdoGroup($rdoGroupName,$key,$val,$chkTrue,$getKey,$arrRdo)

Post by Goborijung at 2021-03-19 10:31:03 | ID: 1024

// Create Function

function getRdoGroup($rdoGroupName, $key, $val, $chkTrue, $getKey, $arrRdo) { $checked = ($chkTrue == true) ? 'checked' : ''; echo " < div class = 'form-check form-check-inline' > < input class = 'form-check-input' type = 'radio' name = '".$rdoGroupName."' value = '".$val."' $checked > < label class = 'form-check-label' > ".$key." < /label> < /div> "; if (count($arrRdo) > 0) { foreach($arrRdo as $key => $val) { if ($key == @$getKey) { echo " < div class = 'form-check form-check-inline' > < input class = 'form-check-input' type = 'radio' name = '".$rdoGroupName."' value = '".$key."' 'checked' > < label class = 'form-check-label' > ".$val." < /label> < /div> "; } else { echo " < div class = 'form-check form-check-inline' > < input class = 'form-check-input' type = 'radio' name = '".$rdoGroupName."' value = '".$key."' > < label class = 'form-check-label' > ".$val." < /label> < /div> "; } } //end-foreeach } }

// การใช้งาน

include 'class/mainClass.php'; $db = new dbConn(); $ct = new classTools(); //Syntax : $ct->getRdoGroup($rdoGroupName,$key,$val,$chkTrue,$getKey,$arrRdo); $ct->getRdoGroup('section','Fabric','fb',true,@$section,array('ac'=>'Accessory'));

PHP : Function > getThisPage() , thisForm

Post by Goborijung at 2021-04-30 09:35:11 | ID: 1158

Function

function getThisPage() { return $_SERVER["PHP_SELF"]; }

การใช้งาน

include 'class/mainClass..php'; $ct = new classTools(); //Syntax : $ct->getThisPage(); <button class="btn btn-sm btn-danger" type="button" name="reset" onclick="window.location.href='<?=$ct->getThisPage()?>' "><i class="fa fa-times"></i> Reset</button>

PHP : Function > setTableHeader($arrHeader)

Post by Goborijung at 2021-03-19 10:31:21 | ID: 1025

function setTableHeader($arrHeader)
{
	echo "<thead style='background-color:#80b4c5;'><tr>";
	foreach($arrHeader as $val)
	{
		echo "<th>".$val."</th>";
	}
	echo "</tr></thead>";
}

// การใช้งาน

$ct->setTableHeader($arrHeader);

PHP : Function > Class dbConn , classTools , mainClass

Post by Goborijung at 2021-03-19 10:18:16 | ID: 1017

include 'class/mainClass.php';
$db = new dbConn();
$ct = new classTools();

// การใช้งาน

$arrBranch = array(
  'NULL' => '', 'SAI4' => 'SAI4', 'SAI4-2' => 'SAI4-2', '304' => '304', 'RAMA2' => 'RAMA2', 'TUW' => 'TUW'
);
$db->getCbo_arrList('cboName',$arrBranch ,@$cboName);

PHP : Function > getCbo_Year($cboName,$getPost)

Post by Goborijung at 2021-03-19 10:29:58 | ID: 1020

function getCbo_Year($cboName,$getPost)
		{
			include 'config.php';
			$sql = "Select Code From Year Where GCRecord is null";
			$qry = sqlsrv_query($conn,$sql);
			if($qry)
			{
				echo "<select name='".$cboName."' id='".$cboName."' class='form-control'>";
				while($rs = sqlsrv_fetch_array($qry))
				{
					if($rs['Code'] == @$getPost)
					{
						echo "<option value='".$rs['Code']."' selected>".$rs['Code']."</option>";
					}
					else
					{
						echo "<option value='".$rs['Code']."'>".$rs['Code']."</option>";
					}
				}
				echo "</select>";
			}
		}

// การใช้งาน

$db->getCbo_Year($cboName,$getPost);

PHP : Get Array to List

Post by Goborijung at 2021-05-31 10:24:50 | ID: 1223

// ตัวอย่าง

$inOID = ""; foreach($id as $val) { $inOID .= $val.','; } $final_inOID = substr($inOID,0,strlen($inOID)-1); //echo $final_inOID; br();

PHP : get Day , get Month , get Year , getDate , strtotime

Post by Goborijung at 2021-05-31 13:21:19 | ID: 1226

<?php
$proDate = date_format($rs['ProbationEndDate'],'Y-m-d');
$getDay = strtotime($proDate);
$day = date('d',$getDay); // หรือ date('d',strtotime($proDate));
echo $proDate.' , '.$day; br();
?>

<<<12345678910...>>>

Framework

Library


เครื่องมือพัฒนาเว็บ



การออกแบบและพัฒนาเว็บไซต์


Download SourceCode



copyAllright © 2016 soundmk.com