我有一个数组,列出了设定日期(2 周支付期)的 14 个日期:
$punchCard = array();
Array(
[1] => Array(
[showDate] => 2012-12-04
[codeDate] => 20121204)
[2] => Array(
[showDate] => 2012-12-05
[codeDate] => 20121205)
.........................................
[12] => Array(
[showDate] => 2012-12-15
[codeDate] => 20121215)
[13] => Array(
[showDate] => 2012-12-16
[codeDate] => 20121216)
[14] => Array(
[showDate] => 2012-12-17
[codeDate] => 20121217)
)
我想遍历它并从数据库中返回一些数据:
foreach($punchCard as $date){
$sql = "
SELECT date, time
FROM `timeclock`
WHERE `employee`=" . $_SESSION['id'] . "
AND `date`=" . (int)$date['codeDate'] . "
ORDER BY `time` ASC ";
$result = mysql_query($sql);
$timecard = array();
while($row = mysql_fetch_assoc($result)){
$timecard[] = $row;
}
}
那是行不通的,但是:
$sql = "
SELECT date, time
FROM `timeclock`
WHERE `employee`=" . $_SESSION['id'] . "
AND `date`=20121204
ORDER BY `time` ASC ";
不知何故(int)$date['codeDate']
不起作用,但我无法理解它,这可能很简单......
泰勒耶斯