我有两张桌子:
comments: id, username, autorpost, comment, id_post, time
posts: id, autorid, autor, date, longitude, latitude, title, text, town, time
现在我想只选择表格帖子的这些行,其中我在cookie $username = $_COOKIE['username'];
中保存的用户名具有与表中用户名相同的值。这可能或者我应该添加任何列吗?
答案 0 :(得分:2)
"SELECT
c.id,
c.username,
c.autorpost,
c.comment,
c.id_post,
c.time,
p.id,
p.autorid,
p.autor,
p.date,
p.longitude,
p.latitude,
p.title,p.text,p.town,p.time
from comments c
JOIN posts p
on p.id=c.id_post
where c.username='".$username."'";
答案 1 :(得分:1)
执行此查询以获取存储在cookie中的用户的帖子。
select Post.* from posts as Post
Left Join
comments as Comment on Post.id = Comment.id_post
where
Comment.username = $_COOKIE['username'];
答案 2 :(得分:0)
您可以使用以下代码剪切 -
{{1}}
而不是*使用您想要访问的相应颜色