 |
code ที่มัน Error ใครรู้ช่วยหน่อยครับ Code Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in |
|
 |
|
|
 |
 |
|
Code
<?php
if (!isset($GET["y"])){
$year = date('Y');
}
else{
$year = $GET["y"];
}
$link = mysql_connect('localhost','root','191130');
if(!$link){
die('Could not connected'.mysql_error());
}
//echo 'Connected successfully';
mysql_select_db("radius");
/*
$strSql="SECECT Distinct GroupName FROM usergroup u";
$result = mysql_query($strSql);
echo $year;
echo "<table border = 1>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
echo"<tr><td>".$row["GroupName"]."<td>";
for($month=1;$month<=12;$month++) {
$strSql2= " SELECT GroupName,Year(AcctStartTime)As year,Month(AcctStartTime)As month ,Count(*)As Count FROM radius.radacct, radius.usergroup u where radius.UserName= u.UserName Group by GroupName,Year(AcctStartTime),Month(AcctStarTime) Having year = ".$year."and month = ".Month."and GroupName = ".$row["GroupName"]."";
$result2 = mysql_query($strSql2);
$num_rows = mysql_num_rows($result2);
if($num_row == 0) {
$row2["Count"]=0;
}
else{
$row2=mysql_fetch_array($result2);
}
echo "<td>".$row2["Count"]."</td>";
}
echo "</tr>";
}
echo "</table>";
*/
$data =array();
$strSql="SELECT GroupName,Year(AcctStartTime)As year,Month(AcctStartTime)As month,Count(*)As count From radius.radacct,radius.Usergroup u where radacct.UserName = u.UserName Group by GroupName,Year(AcctStartTime),Month(AcctStarTime) Having year = ".$year."";
$result = mysql_query($strSql);
echo"<table border = 1>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
echo "<tr>";
echo "<td>".$row["GroupName"]."</td>";
echo "<td>".$row["year"]."</td>";
echo "<td>".$row["month"]."</td>";
echo "<td>".$row["count"]."</td>";
echo "</tr>";
$data[$row["GroupName"]][$row["year"]][$row["month"]]=$row["count"];
}
echo "</table>";
echo $year;
echo "<table border = 1>";
echo "<tr>";
echo "<th>UserName</th>";
echo "<th>Jan</th>";
echo "<th>Feb</th>";
echo "<th>Mar</th>";
echo "<th>Apr</th>";
echo "<th>May</th>";
echo "<th>Jun</th>";
echo "<th>Jul</th>";
echo "<th>Aug</th>";
echo "<th>Sep</th>";
echo "<th>Oct</th>";
echo "<th>Nov</th>";
echo "<th>Dec</th>";
echo "</tr>";
foreach($data as $GroupName=>$val){
echo "<tr>";
echo "<td>$GroupName</td>";
foreach($val as $year=>$val2){
//print "Key $year,Value $val2\n";
//echo "<td>$year</td>";
//foreach($val2 as $month=>$val3){
for($month=1;$month<=12;$month++){
//echo "<td>$month =val3</td>";
//echo "<td>$val3</td>";
if(isset($data[$GroupName][$year][$month])){
echo "<td>".$data[$GruopName][$year][$month]."</td>";
}
else{
echo "<td>0</td>";
}
}
}
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
mysql_close($link)
?>
ปัญหาที่เกิด
1. Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Krasnoyarsk' for '7.0/no DST' instead in C:\AppServ\www\test.php on line 3
2. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\test.php on line 48
2009UserName Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
3. Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\test.php on line 98
ใครรู้ช่วยบอกหน่อยครับต้องแก้ตรงไหน
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-04-23 10:29:11 |
By :
ragnaroknong |
View :
2272 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
if (!isset($_GET["y"])){ // แก้ตรงนี้
$year = date('Y');
}else{
$year = $_GET["y"]; // แก้ตรงนี้
}
$link = mysql_connect('localhost','root','191130');
if(!$link){
die('Could not connected'.mysql_error());
}
//echo 'Connected successfully';
mysql_select_db("radius");
/*
$strSql="SECECT Distinct GroupName FROM usergroup u";
$result = mysql_query($strSql);
echo $year;
echo "<table border = 1>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
echo"<tr><td>".$row["GroupName"]."<td>";
for($month=1;$month<=12;$month++) {
$strSql2= " SELECT GroupName,Year(AcctStartTime)As year,Month(AcctStartTime)As month ,Count(*)As Count FROM radius.radacct, radius.usergroup u where radius.UserName= u.UserName Group by GroupName,Year(AcctStartTime),Month(AcctStarTime) Having year = ".$year."and month = ".Month."and GroupName = ".$row["GroupName"]."";
$result2 = mysql_query($strSql2);
$num_rows = mysql_num_rows($result2);
if($num_row == 0) {
$row2["Count"]=0;
}
else{
$row2=mysql_fetch_array($result2);
}
echo "<td>".$row2["Count"]."</td>";
}
echo "</tr>";
}
echo "</table>";
*/
$data =array(); // แล้วนี้array อะไร
$strSql="SELECT GroupName,Year(AcctStartTime)As year,Month(AcctStartTime)As month,Count(*)As count From radius.radacct,radius.Usergroup u where radacct.UserName = u.UserName Group by GroupName,Year(AcctStartTime),Month(AcctStarTime) Having year = ".$year."";
$result = mysql_query($strSql);
echo"<table border = 1>";
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
echo "<tr>";
echo "<td>".$row['GroupName']."</td>";
echo "<td>".$row['year']."</td>";
echo "<td>".$row['month']."</td>";
echo "<td>".$row['count']."</td>";
echo "</tr>";
$data[$row["GroupName"]][$row["year"]][$row["month"]]=$row["count"];// ลองดูตรงนี้หน่อยนะครับงงมากเลย
}
echo "</table>";
echo $year;
echo "<table border = 1>";
echo "<tr>";
echo "<th>UserName</th>";
echo "<th>Jan</th>";
echo "<th>Feb</th>";
echo "<th>Mar</th>";
echo "<th>Apr</th>";
echo "<th>May</th>";
echo "<th>Jun</th>";
echo "<th>Jul</th>";
echo "<th>Aug</th>";
echo "<th>Sep</th>";
echo "<th>Oct</th>";
echo "<th>Nov</th>";
echo "<th>Dec</th>";
echo "</tr>";
foreach($data as $GroupName=>$val){
echo "<tr>";
echo "<td>$GroupName</td>";
foreach($val as $year=>$val2){
//print "Key $year,Value $val2\n";
//echo "<td>$year</td>";
//foreach($val2 as $month=>$val3){
for($month=1;$month<=12;$month++){
//echo "<td>$month =val3</td>";
//echo "<td>$val3</td>";
if(isset($data[$GroupName][$year][$month])){
echo "<td>".$data[$GruopName][$year][$month]."</td>";
}
else{
echo "<td>0</td>";
}
}
}
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
mysql_close($link); // แก้ตรงนี้
?>
ก็ลองดูนะครับ บอกตรง ๆ ผมดูแล้วยังงงเลย
|
 |
 |
 |
 |
Date :
2009-04-23 13:07:27 |
By :
mosaddzero |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ Appserv 2.6 ใช่ปะครับ
อิอิเปลี่ยนไปใช้ 2.5.9 จะดีกว่าครับ date() ใช้ไม่ได้ error แบบนั้นแหละ
|
 |
 |
 |
 |
Date :
2009-04-25 15:48:25 |
By :
teez1232002 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่านะ
ข้อ 1 ลองแก้ใน php.ini ก่อนนะครับ บรรทัดที่ เขียนว่า "date.timezone"
ถ้าเจอ ";date.timezone =" ให้เปลี่ยนเป็น "date.timezone = Asia/Bangkok" ดูก่อนครับ
อาจจะแก้ปัญหาข้อ 1 ได้ (มั้ง แหะๆ)
ส่วนข้อ 2,3 เกิดจาก sql ที่คุณเขียน ผิด ทำให้ mysql_query แล้วไม่ได้ resource อะไรออกมา
mysql_fetch_array() ก็เลย error
mysql_free_result() ก็เลย error
ข้อแนะนำ
ให้ echo sql ออกมาแล้ว copy ไปลองรันใน phpMyAdmin ดู
ถ้า error มันก็จะบอกในนั้นเลยคับ
|
 |
 |
 |
 |
Date :
2009-04-25 16:18:35 |
By :
nut_t02 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|