 |
ช่วยดูให้หน่อยครับ มันติดตรงไหนไม่รูั้้ ผม select จากตารางนึงแล้ว มา insert อีกตารางนึง ปรากฏว่า insert ลงไม่ครบ |
|
 |
|
|
 |
 |
|
จากโค๊ดนะครับ ผมได้ทำการ select จากตาราง year55 ซึ่งประกอบด้วยฟิวด์ข้อมูล ดังภาพ

อันนี้เป็นโค๊ด select จากตาราง year55 แล้วนำมาลูป เพื่อนำข้อมูลจากการ select ไป insert ในตาราง empfund2 ครับ
Code (PHP)
<?
include('connect.php');
$xmonth[12];
$xmonth[0]="jan";$xmonth[1]="feb";$xmonth[2]="mar";$xmonth[3]="apr";$xmonth[4]="may";
$xmonth[5]="jun";$xmonth[6]="jul";$xmonth[7]="aug";$xmonth[8]="sep";$xmonth[9]="oct";$xmonth[10]="nov";$xmonth[11]="dec";
$sql="select CITIZEN_ID from year55 ";
//$qr=odbc_exec($conn,$sql);
$qr = mysql_query($sql);
$i=1;
while($rs=mysql_fetch_array($qr))
{
$yeartable="year55";
$sql1="select * from $yeartable where CITIZEN_ID='".$rs["CITIZEN_ID"]."'";
//$qr1=odbc_exec($conn,$sql1);
//$num=odbc_num_rows($qr1);
$qr1 = mysql_query($sql1);
$num = mysql_num_rows($qr1);
while($rs1=mysql_fetch_array($qr1))
{
if($num !=0)
{
for($j=0;$j<=12;$j++)
{
$sql2="select ".$xmonth[$j]." from year55 where CITIZEN_ID='".$rs["CITIZEN_ID"]."'";
// $qr2=odbc_exec($conn,$sql2);
// $rs2=odbc_fetch_array($qr2);
$qr2 = mysql_query($sql2);
$rs2=mysql_fetch_array($qr2);
$xxmonth=$xmonth[$j];
$sql3="Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('".$rs["CITIZEN_ID"]."', '".($j+1)."','2012',".$rs2[$xxmonth].")";
if(!mysql_query($sql3))
{
echo $i.". [".$rs1["ID"]."] ".$sql3."<br>";
}
//echo $i.". ".$sql3."<br>";
//echo $i.". ".$rs["stf_fname"]."--".$rs["stf_lname"]."<br>";
$i++;
}
}
}
mysql_free_result($qr1);
//$i++;
}
mysql_free_result($qr)
?>
ผลลัพที่ได้ก็ดังในดังภาพนี้เลยครับ ตาราง empfund2

ผลปรากฏว่า เดือนที่ได้จากการ select มีเพียง เดือนที่ 1-11 ครับ เดือน 12 หายไป
1. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '1','2012',171)
2. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '2','2012',171)
3. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '3','2012',192)
4. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '4','2012',192)
5. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '5','2012',192)
6. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '6','2012',192)
7. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '7','2012',0)
8. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '8','2012',0)
9. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '9','2012',0)
10. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '10','2012',0)
11. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '11','2012',0)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\reservlocal\ProcessOfEmpfund.php on line 29
ลงในฐานข้อมูลเพียงแค่ 11 ค่า อันที่จริงมันต้อง 12 ค่า ไม่รู้ว่าผิดส่วนไหนครับ
Tag : PHP, MySQL, JavaScript
|
|
 |
 |
 |
 |
Date :
2012-08-10 11:06:26 |
By :
compiak |
View :
1046 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จาก code ลอง echo ค่าที่จะ insert ออกมาประกอบดูด้วยครับว่ามันออก เหมือน หรือ แตกต่างกับที่ต้องการหรือเปล่า...
จะได้เห็นภาพว่ามีค่าอะไรบ้างที่เรา selscet ออกมาก่อน insert จะได้หาจุดผิดถูกครับ
|
 |
 |
 |
 |
Date :
2012-08-10 12:02:00 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
1. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '1','2012',171)
2. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '2','2012',171)
3. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '3','2012',192)
4. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '4','2012',192)
5. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '5','2012',192)
6. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '6','2012',192)
7. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '7','2012',0)
8. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '8','2012',0)
9. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '9','2012',0)
10. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '10','2012',0)
11. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '11','2012',0)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\reservlocal\ProcessOfEmpfund.php on line 29
12. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1100400125304', '12','2012',)
13. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '1','2012',378)
14. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '2','2012',378)
15. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '3','2012',378)
16. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '4','2012',378)
17. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '5','2012',378)
18. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '6','2012',378)
19. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '7','2012',0)
20. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '8','2012',0)
21. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '9','2012',0)
22. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '10','2012',0)
23. [] Insert into empfund2(CITIZEN_ID,fund_month,fund_year,debit_value) Values ('1101100001619', '11','2012',0)
ดูเหมือนว่า ค่า CITIZEN_ID อีกค่ากลายเป็นว่า ไปขึ้น Loop ใหม่ซะงั้น มึนตึบ
|
ประวัติการแก้ไข 2012-08-10 12:12:38 2012-08-10 12:13:00
 |
 |
 |
 |
Date :
2012-08-10 12:10:59 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จากโค๊ด ผมลอง echo โค๊ดที่จะต้องทำการ insert เข้าไป
echo $sql2. "<br>" ;
ปรากฏว่า loop แรก ทำไมมีแค่ 11 ซึ่ง select dec from year55 where CITIZEN_ID='1100400125304' ไปอยู่อีกบรรทัดนึงครับ
งง มึน
select jan from year55 where CITIZEN_ID='1100400125304'
select feb from year55 where CITIZEN_ID='1100400125304'
select mar from year55 where CITIZEN_ID='1100400125304'
select apr from year55 where CITIZEN_ID='1100400125304'
select may from year55 where CITIZEN_ID='1100400125304'
select jun from year55 where CITIZEN_ID='1100400125304'
select jul from year55 where CITIZEN_ID='1100400125304'
select aug from year55 where CITIZEN_ID='1100400125304'
select sep from year55 where CITIZEN_ID='1100400125304'
select oct from year55 where CITIZEN_ID='1100400125304'
select nov from year55 where CITIZEN_ID='1100400125304'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\reservlocal\ProcessOfEmpfund.php on line 28
select dec from year55 where CITIZEN_ID='1100400125304'
select jan from year55 where CITIZEN_ID='1101100001619'
select feb from year55 where CITIZEN_ID='1101100001619'
select mar from year55 where CITIZEN_ID='1101100001619'
select apr from year55 where CITIZEN_ID='1101100001619'
select may from year55 where CITIZEN_ID='1101100001619'
select jun from year55 where CITIZEN_ID='1101100001619'
select jul from year55 where CITIZEN_ID='1101100001619'
select aug from year55 where CITIZEN_ID='1101100001619'
select sep from year55 where CITIZEN_ID='1101100001619'
select oct from year55 where CITIZEN_ID='1101100001619'
select nov from year55 where CITIZEN_ID='1101100001619'
|
 |
 |
 |
 |
Date :
2012-08-10 13:04:28 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
up ๆๆๆ  
|
 |
 |
 |
 |
Date :
2012-08-10 13:34:26 |
By :
compiak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|