我有两个 MYSQL 查询:
1) "SELECT ID,post_title,post_category,post_perma FROM ".TBL_POSTS."
WHERE published='1' AND page='0' ORDER BY ID ASC LIMIT 50"
2) "SELECT p.cat_ID,p.cat_nicename FROM ".TBL_CATEGORIES." n,
".TBL_CATEGORIES." p
WHERE n.lft BETWEEN p.lft
AND p.rgt AND n.cat_ID='".post_category."' ORDER BY p.lft
我这样使用它:
$sql="SELECT ID, post_title, post_category,post_perma
FROM ".TBL_POSTS."
WHERE published='1'
AND page='0'
ORDER BY ID ASC LIMIT 50";
$result=mysql_query($sql);
while($row=mysql_fetch_assoc($result)){
$sql2="SELECT p.cat_ID, p.cat_nicename
FROM ".TBL_CATEGORIES." n, ".TBL_CATEGORIES." p
WHERE n.lft BETWEEN p.lft
AND p.rgt
AND n.cat_ID='".$row['post_category']."'
ORDER BY p.lft";
$result2=mysql_query($sql2);
while($row2=mysql_fetch_assoc($result2)){
$path.='/'.$row2['cat_nicename'];
}
$link.='<a href="'.$path.'">'.$row['post_title'].'</a><br>';
$path='';
}
echo($link);
exit;
}
这就是我在链接中获取路径的方式..现在我想要的是:
我想组合这两个查询,所以我没有在 while 循环中运行第二个查询。它变得非常糟糕,因为如果我收到 100 个帖子。第二个查询将运行 100 次以获取路径。