$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 as firstpost”这类事情,并按相同类型的数据对其进行排序。
我正在这样做:
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>';
}
}
解决
关于php - 如何使用PHP操作此SQL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28642097/