$lastquery = $db->query("
(SELECT l.pid as firstpost, l.islike as islike, t.username as username, l.thumbsup, t.subject as subject, l.dateline as dateline
FROM ".TABLE_PREFIX."thumbspostrating l
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.firstpost = l.pid)
WHERE thumbsup)
UNION
(SELECT t.firstpost, ' ' as islike, t.username as username, ' ' as nomames, t.views as views, t.dateline as dateline
FROM ".TABLE_PREFIX."threads t)
ORDER BY dateline DESC
LIMIT ".(($page-1)*$perpage).", ".$perpage);
while ($post = $db->fetch_array($lastquery)) {
if ($post['islike'] == 1) {
$template .= 'This is a like '.$post['firstpost'].'<br><br>';
}
else {
$template .= 'This is a post '.$post['firstpost'].' and '.$post['views'].'<br><br>';
}
}
echo $template;
我只想分离线程帖子的喜欢帖子
像这样:
$post['views'] <-- from second UNION,
$post['pid'] <-- from the first table
我知道我可以做这种事情"l.pid 作为第一个帖子",并按相同类型的数据排序。
我正在这样做:
if ($post['islike'] == 1) {
$template .= 'This is a like '.$post['firstpost'].'<br><br>';
}
else {
$template .= 'This is a post '.$post['firstpost'].' and '.$post['views'].'<br><br>';
}
我错过了什么?
$lastquery = $db->query("
SELECT l.dateline as dateline, l.islike, u.username as username
FROM ".TABLE_PREFIX."thumbspostrating l
LEFT JOIN ".TABLE_PREFIX."threads t ON (t.firstpost = l.pid)
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = l.uid)
UNION
SELECT t.dateline as dateline, ' ', u.username as username
FROM ".TABLE_PREFIX."threads t
LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid = t.uid)
ORDER BY dateline DESC
LIMIT ".(($page-1)*$perpage).", ".$perpage);
while ($post = $db->fetch_array($lastquery)) {
if ($post['islike'] == 1) {
$template .= 'Esto es un like '.$post['dateline'].' user '.$post['username'].'<br><br>';
}
else {
$template .= 'Esto es un post '.$post['dateline'].' ademas '.$post['username'].'<br><br>';
}
}
解决
您需要在第二个请求中选择与第一个请求相同的列。如果您需要其他值,则需要在第一个请求中添加这些列。简而言之 - 使用另一个条件复制第一个请求。剂量不大 您的别名如何命名第二个请求的值将由第一个请求别名以相同的顺序提供。