Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 978337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:02:37+00:00 2026-05-16T04:02:37+00:00

I’ve been trying to count how many times a tag has been entered into

  • 0

I’ve been trying to count how many times a tag has been entered into the database and display the number of times it has been entered along with the tag into the database just like here on StackOverflow but I can’t seem to be able to do it can someone help me?

So far I can get the tag but not the count.

Thanks in advance for the help!

Here is my MySQL & PHP code.

$dbc = mysqli_query($mysqli,"SELECT tags.*, posts_tags.* 
                             FROM tags 
                             INNER JOIN posts_tags ON tags.id = posts_tags.tag_id
                             GROUP BY tags.tag
                             ORDER BY tags.tag ASC");

if (!$dbc) {
    print mysqli_error($mysqli);
}

while($row = mysqli_fetch_assoc($dbc)) {
    $tag = $row['tag'];

    echo '<a href="http://localhost/tags/">' . $tag . '</a>';

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:02:38+00:00Added an answer on May 16, 2026 at 4:02 am

    You may want to try the following:

    SELECT      tags.tag, COUNT(DISTINCT posts_tags.post_id) as number_of_tags
    FROM        tags 
    INNER JOIN  posts_tags ON tags.id = posts_tags.tag_id
    GROUP BY    tags.tag
    ORDER BY    tags.tag ASC;
    

    Test case:

    CREATE TABLE tags (id int, tag varchar(10));
    CREATE TABLE posts_tags (post_id int, tag_id int);
    
    INSERT INTO tags VALUES (1, 'javascript');
    INSERT INTO tags VALUES (2, 'php');
    INSERT INTO tags VALUES (3, 'mysql');
    
    INSERT INTO posts_tags VALUES (1, 1);
    INSERT INTO posts_tags VALUES (2, 2);
    INSERT INTO posts_tags VALUES (3, 1);
    INSERT INTO posts_tags VALUES (4, 2);
    INSERT INTO posts_tags VALUES (5, 3);
    INSERT INTO posts_tags VALUES (6, 1);
    INSERT INTO posts_tags VALUES (7, 1);
    INSERT INTO posts_tags VALUES (8, 2);
    INSERT INTO posts_tags VALUES (9, 2);
    INSERT INTO posts_tags VALUES (10, 1);
    

    Result:

    +------------+----------------+
    | tag        | number_of_tags |
    +------------+----------------+
    | javascript |              5 |
    | mysql      |              1 |
    | php        |              4 |
    +------------+----------------+
    3 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.