|
|
|
ช่วยแก้โค้ดหน่อยคะ ต้องพบอาจารย์พรุ่งนี้เเล้ว T^T มันติดerror เเละไม่โชว์ข้อมูลคะ |
|
|
|
|
|
|
|
ขึ่น เเบบนี้คะ
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\salonss\emp1_report.php on line 99
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\salonss
Code (PHP)
<?
session_start();
include "connect.php";
$branch=$_GET[branch];
$emp=$_GET[emp];
?>
<div id="sidebar">
<td valign='top' style='padding-left:10px; padding-right:10px'>
<div class="info" ><span class="welcome-message"><strong><p><u>รายงานรวมผู้ช่วยช่าง</u><br></p><br>
</div>
<?
?>
<table width="629" class="welcome-message">
<!------เลือกช่าง------>
<tr> <td width="224"><p> เลือกผู้ช่วยช่าง : <label>
<select name="country" class="ntext" id="select" onChange="location.href='report.php?emp='+this.value+'&branch=<?=$branch?>&report=6&month=<?=$month?>';" style="width:200px" >
<option value="0" selected > --เลือกผู้ช่วยช่าง-- </option>
<? //สร้างตัวแปรมาเพื่อไว้รับค่า
$report=$_GET[report]; // แบบรายงาน
$day=$_GET[day]; // วัน/เดือน
$branch=$_GET[branch]; //สาขา
//$change=$_GET[change]; //
$date=$_GET[date]; //วันที่
$month=$_GET[month]; //เดือน
$sql_line1 = "SELECT * FROM employees where BranchID=$branch and PositionID=3 order by EmpName asc;";
$result_line1 = mysql_query($sql_line1) or die("error: ".mysql_error());
while($arr_line1 = mysql_fetch_array($result_line1)) {
$an=$arr_line1[BookingTiME_Date];
$n= explode("-", $an);
$year=$n[2]."-".$n[1]."-".$n[0];
?>
<option value="<?=$arr_line1[EmpID]?>" <? if($arr_line1[EmpID]==$emp){echo "selected"; }?> > <?=$arr_line1[EmpName]?> </option>
<? } // end while ?>
</select></label></p></td>
</tr>
<tr height="30"></tr>
<!------เลือกช่าง1------>
<? if($_GET[emp]){ ?>
<? $total=0;
$total1=0;
$total2=0;
$total3=0;
$total4=0;
$total5=0;
$total6=0;
$total7=0;
$totala=0;
$totala1=0;
$totala2=0;
$totala3=0;
$totala4=0;
$totala5=0;
$count=1;
$dd = date('d-m-Y');
$year=substr($dd,-4,4);
$n= explode("-",$date);
$dayr=$n[2]."-".$n[1]."-".$n[0];
for($i=1;$i<=12;$i++){
if(($month==$i)&&($report==6)){ $ai="0".$i;
$sql2="select t.Name,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d where `BranchID`=$branch and `EmpID_Assis`=$emp and `RecieveTime_Date`
BETWEEN '$year-$ai-01' AND '$year-$ai-31' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by t.Name order by count(t.TypeID) desc";
}
if($_GET[date]!=""){
$sql2="select t.Name,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d where `BranchID`=$branch and `EmpID_Assis`=$emp and `RecieveTime_Date`='$dayr' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by t.Name order by count(t.TypeID) desc";
}
}
$result2=mysql_query($sql2);
?>
<tr class="welcome-message"><td><p>ชื่อช่าง : <? $sql3="select * from employees where EmpID=$emp";
$result3=mysql_query($sql3);
$row3=mysql_fetch_array($result3);
echo $row3[EmpName];
?></p></td></tr>
<tr><td colspan="6"><b>ตารางรวมผู้ช่วยช่างที่ 1</b></td></tr>
<tr>
<td>ชื่อบริการ</td>
<td width="86">จำนวนบริการ</td>
<td width="48">รวมเงิน</td>
<td width="88">ค่าคอมมิชชั่น</td>
<td width="59">ยอดสุทธิ</td>
<td width="96">เรียงลำดับ</td>
</tr>
<?
while($row2= mysql_fetch_array($result2)){
?>
<tr>
<td><? $row2[0];?></td>
<td><? $co=$row2[1]; echo $co;?></td>
<td><? $price=$row2[2]; echo $price; ?></td>
<td><? $com=$row2[3]; $com = round($com,2); echo $com ; ?></td>
<td><? echo $net=$price-$com; ?></td>
<td><?=$count?></td>
</tr>
<?
$total=$total+$price;
$total1=$total1+$com;
$total2=$total2+$cal;
$total3=$total3+$co;
$totala=$totala+$net;
$count++; } ?>
<tr height="30">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>รวม</td>
<td><?=$total3?></td>
<td><?=$total?></td>
<td><?=$total1?></td>
<td><?=$totala?></td>
<td></td>
</tr>
<? } ?>
<!-------------เลือกช่าง 2 --------------->
<tr height="50">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<? if($_GET[emp]){ ?>
<?
$count=1;
$dd = date('d-m-Y');
$year=substr($dd,-4,4);
$n= explode("-",$date);
$dayr=$n[2]."-".$n[1]."-".$n[0];
for($i=1;$i<=12;$i++){
if(($month==$i)&&($report==6)){ $ai="0".$i;
$sql2="select t.Name,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d where `BranchID`=$branch and `EmpID_Assis2`=$emp and `RecieveTime_Date`
BETWEEN '$year-$ai-01' AND '$year-$ai-31' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by t.Name order by count(t.TypeID) desc";
}
if($_GET[date]!=""){
$sql2="select t.Name,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d where `BranchID`=$branch and `EmpID_Assis2`=$emp and `RecieveTime_Date`='$dayr' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by t.Name order by count(t.TypeID) desc";
}
}
$result2=mysql_query($sql2);
?>
<tr><td colspan="6"><b>ตารางรวมผู้ช่วยช่างที่ 2</b></td></tr>
<tr>
<td>ชื่อบริการ</td>
<td>จำนวนบริการ</td>
<td>รวมเงิน</td>
<td>ค่าคอมมิชชั่น</td>
<td>ยอดสุทธิ</td>
<td>เรียงลำดับ</td>
</tr>
<?
while($row2= mysql_fetch_array($result2)){
?>
<tr>
<td><?=$row2[0]?></td>
<td><? $co=$row2[1]; echo $co;?></td>
<td><? $price=$row2[2]; echo $price; ?></td>
<td><? $com=$row2[3]; $com = round($com,2); echo $com ; ?></td>
<td><? echo $net=$price-$com; ?></td>
<td><?=$count?></td>
</tr>
<?
$totala1=$totala1+$price;
$totala2=$totala2+$com;
$totala3=$totala3+$cal;
$totala4=$totala4+$co;
$totala5=$totala5+$net;
$count++; } ?>
<tr height="30">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>รวม</td>
<td><?=$totala4?></td>
<td><?=$totala1?></td>
<td><?=$totala2?></td>
<td><?=$totala5?></td>
<td></td>
</tr>
<tr height="50">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>รวมสุทธิ</td>
<td><? echo $neta1=$total3+$totala4; ?></td>
<td><? echo $neta2=$total+$totala1; ?></td>
<td><? echo $neta3=$total1+$totala2; ?></td>
<td><? echo $neta4=$totala+$totala5; ?></td>
<td></td>
</tr>
<? } ?>
<!------------แสดงทั้งหมดผู้ช่วยช่างที่ 1------------------>
<? if($_GET[day]){ ?>
<? $count=1;
$dd = date('d-m-Y');
$year=substr($dd,-4,4);
$n= explode("-",$date);
$dayr=$n[2]."-".$n[1]."-".$n[0];
for($i=1;$i<=12;$i++){
if(($month==$i)&&($report==6)){ $ai="0".$i;
$sqlall=" select e.EmpName,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d,employees e where s.`BranchID`=$branch and s.`EmpID_Assis`=e.EmpID and `RecieveTime_Date` BETWEEN '$year-$ai-01' AND '$year-$ai-31' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by s.EmpID_Assis order by count(t.TypeID) desc";
}
if($_GET[date]!=""){
$sqlall=" select e.EmpName,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d,employees e where s.`BranchID`=$branch and s.`EmpID_Assis`=e.EmpID and `RecieveTime_Date`='$dayr' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by s.EmpID_Assis order by count(t.TypeID) desc";
}
}
$resultall=mysql_query($sqlall);
$numq= mysql_num_rows($resultall);
?>
<? if($numq!=0){?>
<tr>
<td>ชื่อบริการ</td>
<td>จำนวนบริการ</td>
<td>รวมเงิน</td>
<td>ค่าคอมมิชชั่น</td>
<td>ยอดสุทธิ</td>
<td>เรียงลำดับ</td>
</tr>
<?
while($rowall=mysql_fetch_array($resultall)){
?>
<tr>
<td><?=$rowall[0]?></td>
<td><? $co=$rowall[1]; echo $co;?></td>
<td><? $price=$rowall[2]; echo $price; ?></td>
<td><? $com=$rowall[3]; $com = round($com,2); echo $com ; ?></td>
<td><? echo $to=$price-$com; ?>
<td><?=$count?></td>
</tr>
<?
$total=$total+$price;
$total1=$total1+$com;
$total2=$total2+$cal;
$total3=$total3+$co;
$count++; } ?>
<tr>
<td>รวม</td>
<td><?=$total3?></td>
<td><?=$total?></td>
<td><?=$total1?></td>
<td><? echo $neta=$total-$total1; ?></td>
<td></td>
</tr>
<tr height="30">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<?}else{ echo"<tr align='center'><td colspan='6'> No Data</td></tr>";} ?>
<!------------------------------>
<!------------แสดงทั้งหมดผู้ช่วยช่างที่ 2------------------>
<? $count=1;
$dd = date('d-m-Y');
$year=substr($dd,-4,4);
$n= explode("-",$date);
$dayr=$n[2]."-".$n[1]."-".$n[0];
for($i=1;$i<=12;$i++){
if(($month==$i)&&($report==6)){ $ai="0".$i;
$sqlall=" select e.EmpName,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d,employees e where s.`BranchID`=$branch and s.`EmpID_Assis2`=e.EmpID and `RecieveTime_Date` BETWEEN '$year-$ai-01' AND '$year-$ai-31' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by s.EmpID_Assis2 order by count(t.TypeID) desc";
}
if($_GET[date]!=""){
$sqlall=" select e.EmpName,count(d.TypeID),sum(s.Price),sum(d.commision) from services s,servicetypes t ,servicedetail d,employees e where s.`BranchID`=$branch and s.`EmpID_Assis2`=e.EmpID and `RecieveTime_Date` = '$dayr' and s.ServiceID=d.ServiceID and d.TypeID=t.TypeID group by s.EmpID_Assis2 order by count(t.TypeID) desc";
}
}
$resultall=mysql_query($sqlall);
$numq= mysql_num_rows($resultall);
?>
<? if($numq!=0){?>
<tr>
<td>ชื่อบริการ</td>
<td>จำนวนบริการ</td>
<td>รวมเงิน</td>
<td>ค่าคอมมิชชั่น</td>
<td>ยอดสุทธิ</td>
<td>เรียงลำดับ</td>
</tr>
<?
while($rowall=mysql_fetch_array($resultall)){
?>
<tr>
<td><?=$rowall[0]?></td>
<td><? $co=$rowall[1]; echo $co;?></td>
<td><? $price=$rowall[2]; echo $price; ?></td>
<td><? $com=$rowall[3]; $com = round($com,2); echo $com ; ?></td>
<td><? echo $to=$price-$com; ?>
<td><?=$count?></td>
</tr>
<?
$total4=$total4+$price;
$total5=$total5+$com;
$total6=$total6+$cal;
$total7=$total7+$co;
$count++; } ?>
<tr>
<td>รวม</td>
<td><?=$total7?></td>
<td><?=$total4?></td>
<td><?=$total5?></td>
<td><? echo $netb=$total4-$total5; ?></td>
<td></td>
</tr>
<tr height="30">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>รวมสุทธิ</td>
<td><? echo $net=$total3+$total7;?></td>
<td><? echo $net1=$total+$total4;?></td>
<td><? echo $net2=$total1+$total5;?></td>
<td><? echo $net3=$neta+$netb;?></td>
<td></td>
</tr>
<?}else{ echo"<tr align='center'><td colspan='6'> No Data</td></tr>";} ?>
<!------------------------------>
<? } ?>
</table>
</div>
Tag : PHP, MySQL, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2012-02-09 19:46:40 |
By :
BNforever |
View :
976 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมว่า sql น่าจะผิดคับ
ลองเอาไปยิงใน phpmyadmin เพื่อดูจุดผิดคับ
|
|
|
|
|
Date :
2012-02-09 20:35:11 |
By :
pjgunner.com |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|