Jump to content

Union Issue


Lone_Ranger

Recommended Posts

if ($countnot[0] == "0") {
echo "<p align=center><font size=2>You Currently Have No New Notifications</font></p>";
}
else
{
$union=mysql_query("SELECT date, message, address from notifications where nuser='$row[id]' UNION SELECT date, message, address from blogsnotification where user='$joysong=[friendid]' UNION SELECT date, message, address from inmymind where user='$joysong=[friendid]' UNION SELECT date, message, address from friendsnotification where accountid='$row[id]' ORDER by date DESC LIMIT 0,15") or trigger_error(mysql_error());
$notes = mysql_fetch_array($union);
echo "<table border=0 width=100% cellspacing=0 cellpadding=0>
	<tr>
		<td>
		<table border=0 width=100% cellspacing=0 cellpadding=0>
			<tr>
				<td width=141><p align=right><b>$notes[date]</b></p></td>
				<td width=14> </td>
				<td><p align=center><a href=$notes[address]>$notes[message]</a></p></td>
				<td width=8 bgcolor=#008000> </td>
				<td width=43><p align=center></img></p></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td background=http://www.sentuamessage.com/divider.jpg> </td>
	</tr>
</table>";
 }

The union statement made is working but it only shows the latest result. It does not list the 15 results from the 3 tables like I wanted too. Why is this?

 

 

Link to comment
https://forums.phpfreaks.com/topic/284886-union-issue/
Share on other sites

You might also want to change the two occurences of

WHERE user='$joysong=[friendid]'

to

WHERE user='$joysong[friendid]'

Easier to spot when your query is structured instead of being strung out across the office

$sql = "SELECT date, message, address 
        FROM notifications 
        WHERE nuser='$row[id]' 
    UNION 
        SELECT date, message, address 
        FROM blogsnotification 
        WHERE user='$joysong=[friendid]' 
    UNION 
        SELECT date, message, address 
        FROM inmymind 
        WHERE user='$joysong=[friendid]' 
    UNION 
        SELECT date, message, address 
        FROM friendsnotification 
        WHERE accountid='$row[id]' 
    ORDER by date DESC LIMIT 0,15";
Link to comment
https://forums.phpfreaks.com/topic/284886-union-issue/#findComment-1462915
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.