以下查询有效,但由于某种原因,第一个 select 语句是唯一显示的 URL。显示其他表中的项目,但其 URL 错误。
$sql = "(SELECT postsID as postsID, postsSubject AS postsSubject, postsTimestamp AS timestamp
FROM posts
WHERE postsCategory = '$id')
UNION
(SELECT eventID as eventID, eventTitle as eventTitle, eventsTimestamp as timestamp
FROM events
WHERE eventLocation = '$id')
ORDER BY timestamp DESC";
事件和帖子表中的信息都正确显示,但结果似乎仅来自帖子表。
例如,假设我有以下信息
postsID | postsSubject | postsTimestamp
1 post 123
eventID | eventTitle | eventsTimestamp
2 event 456
我有以下显示我的结果
while($row = mysql_fetch_assoc($result)){
?>
<tr><td><? echo '<a href="viewevent.php?eventID=' . $row['eventID'] . '">' . $row['eventTitle'] . '</a>' ; ?></td>
<tr><td><? echo '<a href="viewpost.php?postID=' . $row['postsID'] . '">' . $row['postsSubject'] . '</a>' ; ?></td>
<?
if(preg_match('/[0-9]/',$row['timestamp'])){
list($yyyy,$dd,$mm) = explode('-',$row['timestamp']);
$newDate = $dd."-".$mm."-".$yyyy;
}
?>
<td><center><? echo $newDate; ?></center></td></tr>
<?
}
echo '</table>';
}
输出似乎是正确的
post 123
event 456
但是,这两个结果都链接到以下内容(分别)
viewpost.php?id = 1
viewpost.php?id = 2 //this should be viewevent.php