我目前正在尝试显示成员上传到我的网站的论文,用户点击一个主题,它会显示该主题下的论文。然而,我的查询只显示了所有的论文,而不是特定主题的论文。
//time to get our info
//time to get our info
$sql = "SELECT paper.title, paper.username, paper.abstract, paper.filelocation FROM `paper`, `topic` WHERE topic_name = 'artificial intelligence' ";
$result = mysql_query($sql);
while($file = mysql_fetch_array($result)){
echo '<li>';
echo '<h1>'.$file['title'].'</h1><br />';
//now the file info and link
echo '<h3>Uploaded By: '.$file['username'].'</h3><br />';
echo '<a href="'.$file['filelocation'].'">'.$file['title'].'</a>';
echo '<h1> Abstract : ' .$file['abstract'].'</h1><br />';
echo '</li>';
}
?>
</ul这是我的表格
paper_id topic_id
主题
topic_id topic__name
纸
paper_id标题用户名抽象文件位置
发布于 2012-04-09 23:25:30
您需要将这两个表连接在一起,并使用一个关键条件将它们链接起来:
SELECT
paper.title,
paper.username,
paper.abstract,
paper.filelocation
FROM `paper`
INNER JOIN `topic` on `paper`.`topic_id` = `topic`.`topic_id`
WHERE topic_name = 'artificial intelligence'否则,您将交叉连接两个表,这将为您提供两个表之间的所有可能的组合。
https://stackoverflow.com/questions/10075476
复制相似问题