|
|
|
สอบถามเรื่อง Update table ค่ะ เข้าลูปแต่ไม่บวกเพิ่มให้ค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
move_uploaded_file($_FILES["fileCSV"]["tmp_name"],$_FILES["fileCSV"]["name"]); // Copy/Upload CSV
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database"); // Conect to MySQL
$objDB = mysql_select_db("inoue");
$objCSV = fopen($_FILES["fileCSV"]["name"], "r");
$tmp = "000000";
while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {
$marker = $objArr[0];
$date = $objArr[1];
if (trim($marker) == "500140"){
$tmp = "500140";
}
if (trim($marker) == "500183") {
$tmp = "500183";
}
if (trim($marker) == "500026") {
$tmp = "500026";
}
if (trim($marker) == "600621") {
$tmp = "600621";
}
if (trim($marker) == "500182") {
$tmp = "500182";
}
if (trim($marker) == "500193") {
$tmp = "500193";
}
if (trim($marker) == "500102") {
$tmp = "500102";
}
if (trim($marker) == "500204") {
$tmp = "500204";
}
if (trim($marker) == "500010") {
$tmp = "500010";
}
if (trim($marker) == "500125") {
$tmp = "500125";
}
if (trim($marker) == "600459") {
$tmp = "600459";
}
if (trim($marker) == "500093") {
$tmp = "500093";
}
//echo $tmp."__".$marker."<br>";
$strSQL = "INSERT INTO barcode_demo ";
$strSQL .="(barcode,address,date_add,Name,status)";
$strSQL .="VALUES ";
$strSQL .="('".$marker."','".$tmp."','".$date."','".$_POST['Name']."','1') ";
$objQuery = mysql_query($strSQL);
$cutdate = substr($date,0,7);
$cutmarker = substr($marker,0,3);
$sqlba = "SELECT * FROM balance where barcode = '$cutmarker'";
$sqlba .= " AND address ='$tmp'";
$sqlba .= " AND date ='$cutdate'";
$dbqueryba = mysql_query($sqlba) or die ("Error Query [".$sqlba."]");
$numrowsba = mysql_num_rows($dbqueryba);
if($numrowsba > 0){
$sqlupdate = "update balance SET amount = amount+1 where barcode = '$cutmarker' and address ='$tmp' and date ='$cutdate'";
}else{
$sqlchk = "INSERT INTO balance";
$sqlchk .="(barcode,address,amount,date,status)";
$sqlchk .="VALUES ";
$sqlchk .="('".$cutmarker."','".$tmp."','1','".$cutdate."','1') ";
$objQuerychk = mysql_query($sqlchk);
}
}
fclose($objCSV);
unlink($_FILES["fileCSV"]["name"]);
echo "Import Done.";
รบกวนด้วยค่ะ ไม่แน่ใจว่าติดตรงไหน ไม่ยอมบวกเพิ่มให้ค่ะ
Tag : PHP
|
|
|
|
|
|
Date :
2014-08-13 17:00:08 |
By :
hlinzaii |
View :
659 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บรรทัด64 amount+1 ลองปรับเป็น amount+'1' ดูนะครับ
|
|
|
|
|
Date :
2014-08-13 20:12:05 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เหมือนเดิมเลยค่ะ แต่ว่าถ้าecho ออกมา แล้ว ลองรันใน phpmyadmin แล้ว amount บวกเพิ่มนะคะ
|
ประวัติการแก้ไข 2014-08-13 21:08:04
|
|
|
|
Date :
2014-08-13 20:43:25 |
By :
hlinzaii |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sqlba = "SELECT * FROM balance where barcode = '$cutmarker'";
$sqlba .= " AND address ='$tmp'";
$sqlba .= " AND date ='$cutdate'";
echo $sqlba; exit; // Check บันทัดนี้เอา echo ที่ได้ ไปคิวรี่ใน phpmyadmin ครับ
$dbqueryba = mysql_query($sqlba) or die ("Error Query [".$sqlba."]");
เจอล่ะซ
64.$sqlupdate = "update balance SET amount = amount+1 where barcode = '$cutmarker' and address ='$tmp' and date ='$cutdate'";
มีแต่ sting แต่ไม่ได้ excute ครับ ไม่ผ่าน mysql_query($sqlupdate);
|
ประวัติการแก้ไข 2014-08-13 21:18:50
|
|
|
|
Date :
2014-08-13 21:13:38 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
if($numrowsba > 0){
$sqlupdate = "update balance SET amount = amount 1 ".
"where barcode = '$cutmarker' and address ='$tmp' and date ='$cutdate'";
mysql_query($sqlupdate); // เพิ่มบันทัดนี้เพื่อ รัน statement ครับ มันยังไม่ได้รันครับเลยไม่มีการเปลี่ยนแปลง
}else{
|
|
|
|
|
Date :
2014-08-14 10:07:43 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|