Jump to content

Need to grab incremental value if 2 OR MORE rows exist


Monkuar

Recommended Posts

$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:

 

123ffh.png

 

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?

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'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.

 

251z.png

 

I need to left join my forums database with my online database:

 

onlinetable.png

 

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.