ฉันมีรหัสใน PHPRunner (หลังจากบันทึกที่อัปเดตแล้ว) เพื่ออัปเดตตารางหลักที่มีจำนวนชั่วโมงทำงานทั้งหมดตามตารางรายละเอียด (หลายรายการ) แต่เมื่อฉันเพิ่มส่วนคำสั่ง sencond WHERE ลงใน $strUpdate ฉันได้รับไวยากรณ์ ข้อผิดพลาด
ฉันเปลี่ยนรหัสหลายครั้งและไม่ทำงานกับส่วนคำสั่ง WHERE และ AND ถ้าฉันลบAND (Date=$values[DateField1])
และนำ () ออก โปรแกรมจะคำนวณผลรวม ปัญหาเดียวก็คือมันจะเพิ่มผลรวมลงในช่องชั่วโมงของตารางหลักทั้งหมดของฉัน แทนที่จะเป็นช่องสำหรับวันที่นั้นเท่านั้น .
$mykey=$values["OwnerID"];
$mykey1=$values["DateField1"];
global $conn;
$str = "เลือก SUM(ชั่วโมง)เป็น [ชม.] จากการเข้าร่วม WHERE OwnerID=\'{$mykey}\' จัดกลุ่มตาม DateField1";
$rs = db_query($str);
$value = db_fetch_numarray($ rs);
$total=$value[0];
$strUpdate = "อัปเดตชุด HrsOT `DailyHrs`=\'{$total}\' โดยที่ ((OwnerID=\'{$mykey} \') AND (Date=$values[DateField1])";
db_exec($strUpdate,$conn);
return true;
ฉันได้ดูโค้ดตัวอย่างและอ่าน หน้าแบบสอบถาม sql / msaccess ออนไลน์และไม่พบสาเหตุของข้อผิดพลาด ความช่วยเหลือใด ๆ ที่ชื่นชมอย่างมาก
2 WHERE clause
นั่นคือข้อผิดพลาด (หรือ) ปัญหาที่นี่ คุณไม่สามารถมีWHERE
2 อนุประโยคในคำสั่ง SQL เดียว เว้นแต่จะเป็นข้อความค้นหาย่อยหรือรูปแบบอื่น แทนที่จะลองผสมเงื่อนไขโดยใช้ตัวดำเนินการเงื่อนไขAND
OR
ฉันไม่สามารถทำให้คิวรีอัปเดตใช้งานได้ ทุกอย่างดูเหมือนปกติดีแต่ตารางไม่ได้รับการอัปเดต หลังจากเปลี่ยนตารางหลายครั้ง ฉันจึงสร้างฟิลด์เชื่อมโยงใหม่ระหว่างมาสเตอร์ และตารางรายละเอียด และทำให้แบบสอบถามของฉันง่ายขึ้นโดยเอาส่วนคำสั่ง AND ออก ทั้งหมดทำงานและโพสต์ที่นี่สำหรับทุกคนที่สนใจ
$mykey=$values["MasterID"];
global $conn;
$str = ("SELECT SUM(Hours) FROM Attendance WHERE
MasterID=$mykey"
);
$rs = db_query($str,$conn);
$value = db_fetch_numarray($rs);
$total=$value[0];
$sql = ("UPDATE HrsOT SET DailyHrs=\'$total\' WHERE
ID=".$values["MasterID"]);
DB::Exec($sql,$conn);
return true;
เพียงกำหนดพารามิเตอร์ของค่าวันที่ ตอนนี้ คุณรวมตัวแปร (รู้จักใน PHP เท่านั้น)$values[DateField1]
โดยตรงในคำสั่ง SQL ไม่เหมือนตัวแปรสองตัวแรกที่คุณสอดแทรกตัวแปรเหล่านี้:$total
และ$mykey
ดังนั้น ในการเรียกใช้แบบสอบถามนี้ โปรแกรม Access จะไม่รู้จักเอนทิตีนี้
อย่างไรก็ตาม หากคุณกำหนดพารามิเตอร์ (หลีกเลี่ยงการต่อข้อมูล) ด้วยคำสั่งที่เตรียมไว้ คุณจะสามารถส่งผ่านค่าของชั้นแอปพลิเคชันไปยังชั้นฐานข้อมูลได้อย่างมีประสิทธิภาพ ด้านล่างนี้คือแถลงการณ์ที่เตรียมไว้ในเวอร์ชัน PHPRunner นอกจากนี้ สำหรับ MS Access วันที่สตริงจะไม่ถูกประเมินหากไม่มีการแปลงด้วยCDate
หรือปิดตัวอักษรด้วย octothorpes,#
ด้านล่างนี้ถือว่า$total
และ$mykey
เป็นตัวเลข
$sql = DB:: PreparSQL(
"UPDATE HrsOT SET [DailyHrs]= :1 WHERE ((OwnerID = \':2\') AND ([Date] = CDate(\':3\'))", \ n $total,
$mykey,
$values[DateField1]
);
DB::Exec( $sql );
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.