我有两个表格wnews和类别。
我想用id
打印类别名称类似于wnews.category(是一个整数)和类别(id,name)的地方 wnews.category = cateroies.id和打印名称
我做了些什么,但我失败了......
$query = mysql_query("SELECT wnews.id, wnews.torrentid, wnews.title,
wnews.img, wnews.added, wnews.category,
wnews.genre, wnews.uploader, wnews.description,
categories.id, categories.name
FROM wnews
INNER JOIN categories
ON wnews.category=categories.id
ORDER BY wnews.added DESC")
or sqlerr();
while ($arr = mysql_fetch_assoc($query))
{ printNews($arr["wnews.torrentid"], $arr["wnews.title"],
$arr["wnews.img"], $arr["wnews.added"],
$arr["categories.name"], $arr["wnews.genre"],
$arr["wnews.uploader"], $arr["wnews.description"]);
}
感谢您的时间。
解决。
$query = mysql_query("SELECT wnews.id, wnews.torrentid, wnews.title, wnews.img, wnews.added,
wnews.category, wnews.genre, wnews.uploader, wnews.description, categories.id, categories.name AS cat_name FROM wnews
LEFT JOIN categories ON wnews.category = categories.id
ORDER BY wnews.added DESC") or die(mysql_error());
while ($arr = mysql_fetch_assoc($query))
{
printNews($arr["torrentid"], $arr["title"], $arr["img"], $arr["added"], $arr["cat_name"], $arr["genre"], $arr["uploader"], $arr["description"]);
}
答案 0 :(得分:0)