รันในเครื่อง แสดงผลได้ แต่พอรับบนเว็บจริง กับ Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource ในส่วนของการ SUM หมดเลยครับ ใครเข้าใจช่วยดูให้ผมหน่อยครับ
Code (PHP)
<?php
session_start();
include "config.php";
// ติดต่อกับฐานข้อมูล
$connection = mysql_connect($dbHost,$dbUser,$dbPass) or die ("Can't Connect database");
$db = mysql_select_db($dbName) or die ("Can't connect database");
mysql_query("SET NAMES 'UTF8'");
?>
<html>
<head>
<title>บันทึกข้อมูลสมาชิกใหม่</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK media=all href="css/style.css" type=text/css rel=stylesheet>
</head>
<BODY>
<div align="center">
<table width="1100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><span class="link1"><a href="register.php" class="link1">บันทึกข้อมูลสมาชิก</a><span class="h5"> | <a href="callcenter.php" class="link1">รับรายการลูกค้า</a> | <a href="deposit_view.php" class="link1">ดูรายการฝาก</a></span></span><br></td>
</tr>
<tr class="f10">
<td align="center"><strong>แสดงรายการฝากเงิน</strong></td>
</tr>
</table>
<table width="1100" border="0" cellspacing="1" cellpadding="0">
<tr class="f9">
<td width="50" align="center"><strong>ลำดับ</strong></td>
<td width="100" align="center"><strong>รหัสสมาชิก</strong></td>
<td width="100" align="center"><strong>ชื่อสมาชิก</strong></td>
<td width="100" align="center"><strong>กสิกรไทย</strong></td>
<td width="100" align="center"><strong>กรุงเทพ</strong></td>
<td width="100" align="center"><strong>กรุงไทย</strong></td>
<td width="100" align="center"><strong>ไทยพาณิชย์</strong></td>
<td width="100" align="center"><strong>ช่องทาง</strong></td>
<td width="100" align="center"><strong>เวลาฝาก</strong></td>
<td width="100" align="center"><strong>พนักงาน</strong></td>
<td width="150" align="center"><strong>วัน / เวลา</strong></td>
</tr>
</table>
<?php
$sql="select * from `".$tb_prefix."deposit` Order by DepositID DESC limit 50 ";
$result=mysql_db_query($dbName,$sql);
while ($record=mysql_fetch_array($result)){
$DepositID=$record[DepositID];
$Username=$record[Username];
$Name=$record[Name];
$KBANK=$record[KBANK];
$BBL=$record[BBL];
$KTB=$record[KTB];
$SCB=$record[SCB];
$Channel=$record[Channel];
$DepositTime=$record[DepositTime];
$Staff=$record[Staff];
$Date=$record[Date];
echo"
<table width=\"1100\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\">
<tr>
<td width=\"50\" class=\"f7\" align=\"center\">$DepositID</td>
<td width=\"100\" class=\"f7\" align=\"center\"><b>$Username</b></td>
<td width=\"100\" class=\"f7\" align=\"center\"><b>$Name</b></td>
<td width=\"100\" class=\"f7\" align=\"right\"><b>$KBANK</b></td>
<td width=\"100\" class=\"f7\" align=\"right\"><b>$BBL</b></td>
<td width=\"100\" class=\"f7\" align=\"right\"><b>$KTB</b></td>
<td width=\"100\" class=\"f7\" align=\"right\"><b>$SCB</b></td>
<td width=\"100\" class=\"f7\" align=\"center\">$Channel</td>
<td width=\"100\" class=\"f7\" align=\"center\">$DepositTime</td>
<td width=\"100\" class=\"f7\" align=\"center\">$Staff</td>
<td width=\"150\" class=\"f7\" align=\"center\">$Date</td>
</tr>
</table>
";
}
?>
<table width="1100" border="0" cellspacing="1" cellpadding="0">
<tr class="f9">
<td width="249" align="center"><strong class="h4">TOTAL =</strong> <b>
<?
$sql="SELECT SUM(KBANK+BBL+KTB+SCB) as punch from (Deposit) ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',',');
}
?>
</b></td>
<td width="100" align="right"><span class="h4"><b>
<?
$sql="select sum(KBANK) as punch from (Deposit) ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',',');
}
?>
</b></span></td>
<td width="97" align="right"><span class="h4"><b>
<?
$sql="select sum(BBL) as punch from (Deposit) ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',',');
}
?>
</b></span></td>
<td width="100" align="right"><span class="h4"><b>
<?
$sql="select sum(KTB) as punch from (Deposit) ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',',');
}
?>
</b></span></td>
<td width="98" align="right"><span class="h4"><b>
<?
$sql="select sum(SCB) as punch from (Deposit) ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',',');
}
?>
</b></span></td>
<td width="97" align="center">ช่องทาง</td>
<td width="98" align="center">เวลาฝาก</td>
<td width="100" align="center">พนักงาน</td>
<td width="151" align="center">วัน / เวลา</td>
</tr>
</table>
<br/>
<table width="293" border="1" cellpadding="1" cellspacing="1">
<tr class="f9">
<th width="142" align="center" scope="col">User</th>
<th width="139" align="center" scope="col">Total</th>
</tr>
<tr class="f2">
<td align="center"><?php
$sql="SELECT Username,SUM(KBANK+BBL+KTB+SCB) as punch FROM Deposit GROUP BY Username Order by Username ";
$result=mysql_db_query($dbName,$sql);
while ($record=mysql_fetch_array($result)){
$Username=$record[Username];
echo"$Username<br>";
}
?></td>
<td align="right"><?php
$sql="SELECT Username,SUM(KBANK+BBL+KTB+SCB) as punch FROM Deposit GROUP BY Username Order by Username ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',','),"<BR>";
}
?></td>
</tr>
</table>
</div>
</body>
</html>
Tag : PHP
Date :
2011-07-16 16:47:26
By :
เอ็ม
View :
701
Reply :
2
มันเออเร่อเฉพาะในส่วนนี้อ่ะครับ ไม่รู้ว่าโค้ดตรงไหนผิด ทั้ง ๆ ที่รันบนเครื่องก็ยังรันได้
Code (PHP)
<?php
$sql="SELECT Username,SUM(KBANK+BBL+KTB+SCB) as punch FROM Deposit GROUP BY Username Order by Username ";
$result=mysql_query($sql);
while($rs=mysql_fetch_array($result)){
echo number_format ($rs['punch'],0,'.',','),"<BR>";
}
?>
Date :
2011-07-16 17:16:13
By :
เอ็ม
Code (PHP)
$result=mysql_query($sql) or die(mysql_error() . '<br/>' . $sql);
ดูว่า error อะไร
ประวัติการแก้ไข 2011-07-16 21:08:02 2011-07-16 21:08:36
Date :
2011-07-16 21:07:04
By :
PlaKriM
Load balance : Server 00