我有一個SQL查詢經過搜索並顯示數百列的記錄。但是兩列的顯示必須改變;生效日期和清除日期。目前它們都是這樣顯示的:(例如1991年8月29日)。我想將輸出更改爲1991年8月29日。我不確定我會怎麼做,因爲它將數據直接從數據庫中提取到表中。
請注意我在這個項目中使用MS-SQL和PHP。從SQL查詢更改PHP頁面上的顯示
這是我的SQL查詢:
$sql = "select SerialNum as [Serial Number],ts_sitename As Site,(case m.Scratched
when 0 then 'Live'
when 1 then 'Free'
END) as Status, Note as Comment, (case Destroyed when 0 then 'NO'
when 1 then 'YES' END) as [Destroyed],
SUBSTRING(cast(mg_effectivedate as char), 1, 12) AS [Effective Date],
SUBSTRING(cast(mg_effectivedate as char), 12, 8) AS [Effective Time],
SUBSTRING(cast(ScratchedDate as char), 1, 4) + '-' +
SUBSTRING(cast(ScratchedDate as char), 3, 2) + '-' +
SUBSTRING(cast(ScratchedDate as char), 5, 2)
AS [Scratched Date],
SUBSTRING(cast(ScratchedDate as char), 10, 2) + ':' +
SUBSTRING(cast(ScratchedDate as char), 12, 2) + ':' +
SUBSTRING(cast(ScratchedDate as char), 14, 2)
AS [Scratched Time],
SUBSTRING(cast(mg_scratchdate as char), 1, 12) AS [Purge Date],
(select fl_filename from TheFiles_tab where mg_filenum = fl_filenum) as [Dataset],
(select hs_hostname from TheHosts_tab where mg_hostnum = hs_hostnum) as [Host],
(select UserCode from [User] where mg_usernum = UserId) as [UserCode]
from ((Media m left join MediaGenT g on m.MediaId = g.mg_medianum)
join TheSites_tab s on m.SiteId = s.ts_sitenum)
join Note n on m.NoteId = n.NoteId
where SerialNum like '" . $userQuery . "%'";
這我的代碼顯示兩列:
echo '<th>Effective Date</th>';
echo '<th>Purge Date</th>';
foreach ($result as $r)
{
echo "<tr>";
echo "<td>".$r['Serial Number'] . " </td>";
echo "<td>".$r['Site'] . " </td>";
echo "<td>".$r['Status'] . "</td> ";
echo "<td>".$r['Comment'] . " </td>";
echo "<td>".$r['Destroyed'] . " </td>";
echo "<td>".$r['Effective Date'] . " </td>";
echo "<td>".$r['Effective Time'] . "</td> ";
echo "<td>";
if ($r['Scratched Date'] == "") {
echo "NULL";
}
else {
echo $r['Scratched Date'];
} echo "</td>";
echo "<td>" ;
if ($r['Scratched Time'] == "") {
echo "NULL";
}
else {
echo $r['Scratched Time'];
} echo "</td>";
echo "<td>".$r['Purge Date'] . " </td>";
echo "<td>".$r['Dataset'] . "</td> ";
echo "<td>".$r['Host'] . " </td>";
echo "<td>".$r['UserCode'] . " </td>";
echo "<td>".$r['NoteId'] . " </td>";
echo "</tr>";
}
請注意,我是新來的SO社區。我一直使用這個網站進行研究,但第一次剛剛創建了一個帳戶。
你可以使用像'名單($個月,$日,$年)=爆炸($ R [ '生效日']) ;'然後只是'echo(「$ day- $ month- $ year」);'。這是你想要的? – Technoh
@technoh會改變所有記錄的顯示嗎? – user2722215