|
|
|
ช่วยลดโค้ดหน่อยครับ ทำแบบนี้แล้วต้องการ ลดให้โค้ดกระชับแต่แก้ไปมากลัวมั่วทำไงได้บ้างคับ |
|
|
|
|
|
|
|
list($date,$time) = split(" ",odbc_result($result,"Start_opdt"));
if( ($time>='00:00:00.000' )and($time<= '00:59:59.000') ) {
$one = odbc_result($result,"sum_lot")+$one;
}else
if( ($time>='01:00:00.000' )and($time<= '01:59:59.000') ) {
$two = odbc_result($result,"sum_lot")+$two;
}else
if( ($time>='02:00:00.000' )and($time<= '02:59:59.000') ) {
$three = odbc_result($result,"sum_lot")+$three;
} else
if( ($time>='03:00:00.000' )and($time<= '03:59:59.000') ) {
$four = odbc_result($result,"sum_lot")+$four;
}else
if( ($time>='04:00:00.000' )and($time<= '04:59:59.000') ) {
$five = odbc_result($result,"sum_lot")+$five;
}else
if( ($time>='05:00:00.000' )and($time<= '05:59:59.000') ) {
$six = odbc_result($result,"sum_lot")+$six;
}else
if( ($time>='06:00:00.000' )and($time<= '06:59:59.000') ) {
$seven= odbc_result($result,"sum_lot")+$seven;
}else
if( ($time>='07:00:00.000' )and($time<= '07:59:59.000') ) {
$eight = odbc_result($result,"sum_lot")+$eight;
}else
if( ($time>='08:00:00.000' )and($time<= '08:59:59.000') ) {
$nine = odbc_result($result,"sum_lot")+$nine;
}else
if( ($time>='09:00:00.000' )and($time<= '09:59:59.000') ) {
$ten = odbc_result($result,"sum_lot")+$ten;
}else
if( ($time>='10:00:00.000' )and($time<= '10:59:59.000') ) {
$eleven = odbc_result($result,"sum_lot")+$eleven;
}else
if( ($time>='11:00:00.000' )and($time<= '11:59:59.000') ) {
$twelve = odbc_result($result,"sum_lot")+$twelve;
}else
if( ($time>='12:00:00.000' )and($time<= '12:59:59.000') ) {
$thirteen = odbc_result($result,"sum_lot")+$thirteen;
}else
if( ($time>='13:00:00.000' )and($time<= '13:59:59.000') ) {
$fourteen = odbc_result($result,"sum_lot")+$fourteen;
}else
if( ($time>='14:00:00.000' )and($time<= '14:59:59.000') ) {
$fifteen = odbc_result($result,"sum_lot")+$fifteen;
}else
if( ($time>='15:00:00.000' )and($time<= '15:59:59.000') ) {
$sixteen = odbc_result($result,"sum_lot")+$sixteen;
}else
if( ($time>='16:00:00.000' )and($time<= '16:59:59.000') ) {
$seventeen = odbc_result($result,"sum_lot")+$seventeen;
}else
if( ($time>='17:00:00.000' )and($time<= '17:59:59.000') ) {
$eighteen = odbc_result($result,"sum_lot")+$eighteen;
}else
if( ($time>='18:00:00.000' )and($time<= '18:59:59.000') ) {
$nineteen = odbc_result($result,"sum_lot")+$nineteen;
}else
if( ($time>='19:00:00.000' )and($time<= '19:59:59.000') ) {
$twenty = odbc_result($result,"sum_lot")+$twenty;
}else
if( ($time>='20:00:00.000' )and($time<= '20:59:59.000') ) {
$twentyone = odbc_result($result,"sum_lot")+$twentyone;
}else
if( ($time>='21:00:00.000' )and($time<= '21:59:59.000') ) {
$twentytwo = odbc_result($result,"sum_lot")+$twentytwo;
}else
if( ($time>='22:00:00.000' )and($time<= '22:59:59.000') ) {
$twentythree = odbc_result($result,"sum_lot")+$twentythree;
}else
if( ($time>='23:00:00.000' )and($time<= '23:59:59.000') ) {
$twentyfour = odbc_result($result,"sum_lot")+$twentyfour;
}
Tag : PHP, Ms SQL Server 2005
|
|
|
|
|
|
Date :
2012-01-31 14:02:14 |
By :
anue0159 |
View :
1050 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อย่างง่ายๆก็ ใช้ Array มาช่วยครับ
ใช้ 2 ตัวแปรคือ เก็บเวลา จำนวน 24ตัว และเก็บค่าที่คุณresult มาได้ 24 ตัว
เวลาเทียบ if else ก็ประมาณ
Code (PHP)
else if( ($time >= '$Time2[23]' )and($time < '$Time2[24]') )
|
|
|
|
|
Date :
2012-01-31 14:26:33 |
By :
50121680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|