对于PHP和SQL,我是一个初学者,所以请原谅我。试图找出为什么我的SQL语句在传递给tblEmployees.Workgroup的变量时不起作用。当我把" CS Lead" vs变量。如果我需要包含任何其他信息,请告诉我。谢谢!
<?php
include 'header.php'; //Include header
include 'sidebar.php'; //Include sidebar
$workgroup = 'CS Lead';
$stmt = $db->query("SELECT
tblSchedule.CurrentSchedule,
tblSchedule.Login,
tblSchedule.StartTime,
tblSchedule.EndTime,
tblSchedule.Sunday,
tblSchedule.Monday,
tblSchedule.Tuesday,
tblSchedule.Wednesday,
tblSchedule.Thursday,
tblSchedule.Friday,
tblSchedule.Saturday,
tblSchedule.Lunch_Start,
tblSchedule.Lunch_End,
tblSchedule.Brk1_Start,
tblSchedule.Brk1_End,
tblSchedule.Brk2_Start,
tblSchedule.Brk2_End,
tblSchedule.Brk3_Start,
tblSchedule.Brk3_End,
tblSchedule.Lunch2_Start,
tblSchedule.Lunch2_End,
tblSchedule.TM_Day,
tblSchedule.TM_Start,
tblSchedule.TM_End,
tblEmployees.Workgroup
FROM tblSchedule
LEFT JOIN tblEmployees
ON tblSchedule.Login=tblEmployees.Login
WHERE CurrentSchedule='Y' AND tblEmployees.Workgroup = ' . $workgroup . '
LIMIT 100");
$stmt -> execute();
?>
答案 0 :(得分:2)
使用双引号...
$stmt = $db->query("SELECT
tblSchedule.CurrentSchedule,
tblSchedule.Login,
tblSchedule.StartTime,
tblSchedule.EndTime,
tblSchedule.Sunday,
tblSchedule.Monday,
tblSchedule.Tuesday,
tblSchedule.Wednesday,
tblSchedule.Thursday,
tblSchedule.Friday,
tblSchedule.Saturday,
tblSchedule.Lunch_Start,
tblSchedule.Lunch_End,
tblSchedule.Brk1_Start,
tblSchedule.Brk1_End,
tblSchedule.Brk2_Start,
tblSchedule.Brk2_End,
tblSchedule.Brk3_Start,
tblSchedule.Brk3_End,
tblSchedule.Lunch2_Start,
tblSchedule.Lunch2_End,
tblSchedule.TM_Day,
tblSchedule.TM_Start,
tblSchedule.TM_End,
tblEmployees.Workgroup
FROM tblSchedule
LEFT JOIN tblEmployees
ON tblSchedule.Login=tblEmployees.Login
WHERE CurrentSchedule='Y' AND tblEmployees.Workgroup = '$workgroup'
LIMIT 100");
OR
WHERE CurrentSchedule='Y' AND tblEmployees.Workgroup = {$workgroup}