The following query works, but for some reason the first select statement is the only URL being displayed. Items from other tables are displayed, however, their URL is wrong.
$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";
The information is being correctly displayed from both the events and posts table, but the results are appearing to ONLY come from the posts table.
For example, say I have the following info
postsID | postsSubject | postsTimestamp
1 post 123
eventID | eventTitle | eventsTimestamp
2 event 456
I have the following to display my results
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>';
}
The output appears to be correct
post 123
event 456
However, both results link to the following (respectively)
viewpost.php?id = 1
viewpost.php?id = 2 //this should be viewevent.php
sql as below:
when retrieving data,