Monkuar Posted September 4, 2012 Share Posted September 4, 2012 $result = $db->query('SELECT user_id, ident,logged,star,in_forum,type FROM '.$db->prefix.'online ORDER BY logged DESC', true) or error('Unable to fetch online list', __FILE__, __LINE__, $db->error()); while ($pun_user_online = $db->fetch_assoc($result)) { if ($pun_user_online['in_forum'] >= 1){ $inforumids[$pun_user_online['in_forum']] = $i++; } } Database: My echo var_dump($inforumids);: array 36 => null 3 => int 1 I need it to be: 36 => 2 3 = > 1 Hence in my database, 2 users are in in_forum id 36. How to make the $i++ incrementer to grab only the count of the row if it's the same? Quote Link to comment https://forums.phpfreaks.com/topic/268001-need-to-grab-incremental-value-if-2-or-more-rows-exist/ Share on other sites More sharing options...
Jessica Posted September 4, 2012 Share Posted September 4, 2012 I'm confused about what you're trying to accomplish. If you're trying to get a list of how many users are in each forum, you would do SELECT count(in_forum), in_forum FROM '.$db->prefix.'online GROUP BY in_forum Quote Link to comment https://forums.phpfreaks.com/topic/268001-need-to-grab-incremental-value-if-2-or-more-rows-exist/#findComment-1375258 Share on other sites More sharing options...
Monkuar Posted September 4, 2012 Author Share Posted September 4, 2012 I'm confused about what you're trying to accomplish. If you're trying to get a list of how many users are in each forum, you would do SELECT count(in_forum), in_forum FROM '.$db->prefix.'online GROUP BY in_forum I am wanting exactly that, sorry for not being clear enough. Here is my forums database. I need to left join my forums database with my online database: I am trying to make it so let's say if 3 people are in the in_forum id = 27, it will show (3 users browsing) next to the "ViP Forum" Because 3 rows = "27" which = 3 people viewing. Quote Link to comment https://forums.phpfreaks.com/topic/268001-need-to-grab-incremental-value-if-2-or-more-rows-exist/#findComment-1375296 Share on other sites More sharing options...
ManiacDan Posted September 5, 2012 Share Posted September 5, 2012 You don't store a last_access time in your in_forum table. if I log in, view the VIP forum, and then don't come back for 6 months, what's to stop me from being counted in the stats forever? Also, research JOIN conditions. You'll need them to be a decent developer. Quote Link to comment https://forums.phpfreaks.com/topic/268001-need-to-grab-incremental-value-if-2-or-more-rows-exist/#findComment-1375320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.