我有两张桌子:
常见问题解答:
常见问题
我想在第一个表中用外键显示字段“name”。
请帮帮我。
答案 0 :(得分:0)
尝试
SELECT a.name , a.id ,b.An , b.qn FROM Faqcat a JOIN FAQS b ON a.id = b.cat_id
答案 1 :(得分:0)
试一试:
$query = mysql_query("SELECT `faqcat`.`name` from `faqcat` join `faqs` on `faqcat`.`id`=`faq`.`cat_id`");
if(mysql_num_rows($query))
{
while ($row = mysql_fetch_object($query))
{
echo $row->name;
}
}
答案 2 :(得分:0)
将**id**
替换为您想要获取其名称的cat_id:
$ID = "**id**";
$SQL = "SELECT cat.name AS name, faq.cat_id AS id
FROM FAQS faq
JOIN Faqcat cat ON(faq.cat_id = cat.id)
WHERE faq.cat_id = '".$ID."'";
答案 3 :(得分:0)
mysql_query("select * from faqs as a Join faqcats as b ON a.cat_id = b.id where question like '%$term%'" );