所以我有以下查询
query = "SELECT date_format(startPeriod,'%a, %M, %d, %Y') as startDate,
date_format(startTime,'%I:%i%p') as startTime,
date_format(endTime,'%I:%i%p') as endTime,
jobLocation,jobId,
hoursWorked
FROM users,paycheck
WHERE users.userId = '" . $_SESSION['userId'] .
"' AND userId = empId
AND startPeriod IS NOT NULL
ORDER BY paycheck.startPeriod DESC";
问题是startPeriod的某些值(这是一个日期)是null,所以当我运行我的查询时,我不想显示那些为空的日期,但不幸的是,我的表上显示为null的日期。我该如何解决这个问题?
这是我的源文件
上的输出文件 <tr><td></td><td>12:00AM</td><td>12:00AM</td><td>none</td><td>none</td><td>0.00</td></tr>
在第一个tds之间你可以看到它是空的
答案 0 :(得分:2)
您确定插入的数据实际上是NULL,而不只是空字符串吗?
之后将startPeriod IS NOT NULL
替换为TRIM(startPeriod) <> ""
或强>
query = "SELECT date_format(startPeriod,'%a, %M, %d, %Y') as startDate,
date_format(startTime,'%I:%i%p') as startTime,
date_format(endTime,'%I:%i%p') as endTime,
jobLocation,jobId,
hoursWorked
FROM users,paycheck
WHERE users.userId = '" . $_SESSION['userId'] .
"' AND userId = empId
AND (startPeriod != '0000-00-00' OR startPeriod IS NOT NULL)
ORDER BY paycheck.startPeriod DESC";
这可能对你有所帮助。