我有这个代码。。。
$lesson = mysql_query("SELECT * FROM categories WHERE gr='exrcs' ORDER BY title");
$flesson = mysql_fetch_array($lesson);
do {
printf("<a href='exrcs?cat=%s'>%s</a>",$flesson['id'],$flesson['title']);
} while ($flesson = mysql_fetch_array($lesson));
此代码将是"HTML, CSS, PHP
"和其他
但我想要这个"HTML (2), CSS (14), PHP(8)
"和其他
此处(2),(14),(8)
金额发布在类别上
更新您的查询:
SELECT title, count(id) total FROM categories WHERE gr='exrcs' group by title ORDER BY title
或
SELECT concat(title,' (', count(id) ,')') as title FROM categories WHERE gr='exrcs' group by title ORDER BY title
按使用计数和分组
"SELECT cat as title , count(*) FROM categories
WHERE gr='exrcs' group by title ORDER BY title"
"SELECT CONCAT(C.title,'(',COUNT(*),')') FROM categories C INNER JOIN post P ON C.ID= P.cat_id GROUP BY c.title"