以下代码在第二列(STSEL)中返回一个null。当我独立运行SQL语句时,它会按预期返回一个"Y"或"N"。
我不明白它为什么要这么做。非常感谢您的帮助。
注意:我直接回应了$response的结果,它显示为null,所以这不是网格配置造成的。
$where = "a.VER = (SELECT max(e.CVER) FROM prodlib.vercntl e WHERE e.VERDTE <= 20151031)
AND a.LVL2 like 'RRG%' AND substr(a.LVL4,1,2) = '00' AND b.TYPE = 'SCT'
AND d.ST = '$state' AND d.LSEQ = $seq";
$sql = "SELECT LROWID, STSEL, ST, STORE, STNAME, CLSEQ, LVL4
FROM
( SELECT row_number() OVER ( ORDER BY 1 asc ) AS rid, d.LROWID, (CASE WHEN (d.ST is not null) THEN 'Y' ELSE 'N' END) as STSEL, c.ST, a.STOR, a.NAME, c.CLSEQ, a.LVL4
FROM prodlib.smpmt a
LEFT OUTER JOIN prodlib.dmpcv b ON a.ST = substr(b.FD1,1,2)
LEFT OUTER JOIN devlib.pyp280c@ c ON a.st = c.ST
LEFT OUTER JOIN devlib.pyp280l@ d ON c.ST=d.ST AND c.CLSEQ=d.LSEQ AND a.STOR = d.STOR
WHERE $where
) AS t
WHERE (t.rid BETWEEN 1 AND 20) ORDER BY STSEL desc, STORE";
if ($conn) {
$stmt = db2_exec($conn, $sql);
$response = (object) array('page' => $page, 'total' => $total_pages, 'records' =>$rowcount, 'rows' => "");
$response->page = $page;
$response->total = $total_pages;
$response->records = $rowcount;
$i=0;
while ($row = db2_fetch_object($stmt)) {
$response->rows[$i]['id']=trim($row->LROWID);
$response->rows[$i]['cell']=array($row->LROWID, $row->STSEL, $row->ST, $row->STORE, $row->STNAME, $row->CLSEQ, $row->LVL4);
$i++;
}
echo json_encode($response);
非常感谢并致以最良好的问候。
为什么不尝试使用聚结?
http://www.w3schools.com/sql/sql_isnull.asp
coalize(d.ST,'N')用N 替换所有空值
我做了这件事,它很管用。我不知道为什么第一种方法不起作用。
if (is_null($row->ROWID)) {
$STSEL = 'N';
} else {
$STSEL = 'Y';
}
$response->rows[$i]['id'] = trim($row->LROWID);
$response->rows[$i]['cell'] = array($row->LROWID, $STSEL, $row->ST, $row->STORE, $row->STNAME, $row->CLSEQ, $row->LVL4);
$i++;