Jump to content

Need to grab incremental value if 2 OR MORE rows exist


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.