I am having problems with echoing the result from a sql query as links when using UNION ALL.
The tables looks like this:
TABLE: posts
id username date commentTABLE: files
id username date file
The "file" row contains urls to uploaded files.
The code i have for displaying the results:
<?php
$sql="SELECT * FROM posts
UNION ALL
SELECT * FROM files
ORDER BY date DESC LIMIT 100";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<div> <?php echo $rows['comment']; ?> </div>
<div> <a href="<?php echo $rows['file']; ?>"><?php echo $rows['file']; ?></a> </div>
<?php
}
?>
Now everything sorts out in the right order, but the filenames wont be displayed as links, only plain text.
There are no problems, echoing out the links if i run a query on the files table only.
I guess the big question is: How do you display the result from a UNION ALL query as links?
When you perform a UNION query, columns are combined meaning your
commentandfilecolumns will be the same, the resultset name of which will becomment(the first select statement). See http://dev.mysql.com/doc/refman/5.0/en/union.htmlI’d be more inclined to use two separate queries, one against the
poststable and the second againstfiles.