Topic: How can I easy count category in index.php ?

Hi,

I try $num_cats = $db->num_rows($result); but it's always 1 sad

Darmowe forum - Polish free forum hosting

Re: How can I easy count category in index.php ?

Well, there's a variable $cat_count which is already calculated for you at the end of the loop wink
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).

Re: How can I easy count category in index.php ?

Err... $cat_count? tongue

Re: How can I easy count category in index.php ?

elbekko wrote:

Err... $cat_count? tongue

$cat_count is always 1

Darmowe forum - Polish free forum hosting

Re: How can I easy count category in index.php ?

Then you only have one category...

Re: How can I easy count category in index.php ?

sorry, my fault sad

I want to count forums from every category big_smile

Darmowe forum - Polish free forum hosting

Re: How can I easy count category in index.php ?

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.

Re: How can I easy count category in index.php ?

OK...
Find

$cat_count = 0;

Add after

$forum_count = 0;

Find

$item_status = '';

Add after

++$forum_count;

And that should be it.

Re: How can I easy count category in index.php ?

elbekko ok, but I would like to know amount of forums before site is generated roll

Darmowe forum - Polish free forum hosting

Re: How can I easy count category in index.php ?

Bleh, follow Smartys' suggestion then tongue

11

Re: How can I easy count category in index.php ?

Smartys wrote:

Easiest way? Remove the second parameter from the call to $db->query and $db->num_rows will work

Can you give me example ?

Darmowe forum - Polish free forum hosting

Re: How can I easy count category in index.php ?

$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());