Topic: How can I easy count category in index.php ?
Hi,
I try $num_cats = $db->num_rows($result); but it's always 1
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 troubleshooting → How can I easy count category in index.php ?
Hi,
I try $num_cats = $db->num_rows($result); but it's always 1
Well, there's a variable $cat_count which is already calculated for you at the end of the loop
The problem with $db->num_rows is that the query is running unbuffered. Therefore, the results aren't being loaded into memory beforehand (and thus you can't get an easy count).
Err... $cat_count?
Then you only have one category...
sorry, my fault
I want to count forums from every category
Easiest way? Remove the second parameter from the call to $db->query and $db->num_rows will work
Another (better?) way? Add a new variable (for the sake of this, I'll call it $forum_count). Increment it every time you go through another row.
OK...
Find
$cat_count = 0;
Add after
$forum_count = 0;
Find
$item_status = '';
Add after
++$forum_count;
And that should be it.
elbekko ok, but I would like to know amount of forums before site is generated
Bleh, follow Smartys' suggestion then
Easiest way? Remove the second parameter from the call to $db->query and $db->num_rows will work
Can you give me example ?
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.min_posts, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE '.$pun_user['num_posts'].' > f.min_posts AND fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
to
$result = $db->query('SELECT c.id AS cid, c.cat_name, f.min_posts, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE '.$pun_user['num_posts'].' > f.min_posts AND fp.read_forum IS NULL OR fp.read_forum=1 ORDER BY c.disp_position, c.id, f.disp_position', false) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
PunBB Forums → PunBB 1.2 troubleshooting → How can I easy count category in index.php ?
Powered by PunBB, supported by Informer Technologies, Inc.