I have two tables in sql and when I echo them out in php I get a weird result... The desired effect is to echo out intro from table intro and msg from table messages- then organize them by date.
$result = mysql_query("SELECT intro.user_id, intro.date, intro.message_id, intro.intro FROM intro WHERE user_id = {$uid}
UNION SELECT messages.user_id, messages.msg, messages.message_id, messages.date FROM messages
ORDER BY date DESC ");
while($row = mysql_fetch_array($result))
{
echo "<p>".getElapsedTime($row['date'])."</p>
<strong>></strong> <a href=\"outro.php?msg_id=".$row['intro.message_id'].
"\">".$row['intro'] . "</a><br>";
}
Intro table

Messages table


However I'm getting this weird result as displayed above. The top portion that are just dates echoing out is from the table messages. I don't know why this is happening nor how to fix it.
Your UNION is messed up. Try:
SELECT intro.user_id, intro.date, intro.message_id, intro.intro
FROM intro WHERE user_id = {$uid}
UNION
SELECT messages.user_id, messages.date, messages.message_id, messages.msg
FROM messages
ORDER BY date DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With