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 6030717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:04:42+00:00 2026-05-23T05:04:42+00:00

I have user entered tags that go under the table field tags. $sql=SELECT tags

  • 0

I have user entered tags that go under the table field tags.

$sql="SELECT tags from table";
$stmt16 = $conn->prepare($sql);
$result=$stmt16->execute();
while($row = $stmt16->fetch(PDO::FETCH_ASSOC)){ 
echo $tags=$row['tags'];
}

This produces

cool,yes,okcool,yes,ok

because there are 2 entries with the same 3 tags under that field. I want to be able to count how many duplicates there are of each tag such that the result should be cool(2) yes(2) ok(2). Anyone know the proper way to approach this? Should I fetch the results as an array or explode them?

  • 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-23T05:04:43+00:00Added an answer on May 23, 2026 at 5:04 am

    With your current data structure, the answer I’d give is yes: as you said, explode them, and put them into an array.

    $tags = array();
    while($row = $stmt16->fetch(PDO::FETCH_ASSOC)){ 
        foreach(explode(',',$row['tags']) as $tag) {
            if(isset($tags[$tag]) {$tags[$tag]++;} else {$tags[$tag]=1;}
        }
    }
    
    //now you can see how many times each tag occurred...
    foreach($tags as $tag=>$count) {
       print "Tag {$tag} occurred {$count} times<br />";
    }
    

    However, if you can change the database structure, you’ll find it a lot easier to manage your tags if you only have one per DB record. It will make it a lot easier to query them that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a user that entered 12 links into the database but
I have a search method that takes in a user-entered string, splits it at
I have a couple escaped characters in user-entered fields that I can't figure out.
I have an index of titles that I am currently filtering by user entered
I have an iPhone app which submits user entered data to a SQL database.
I have a tag field in my web page, in which user can enter
I have to compare a user entered date, Dt (in mm/dd/yyyy format) with the
I have a paragragh of user entered text in a textarea. line1 line2 line3
I have a table where the user can add rows to it but each
I have a textarea field on my webpage. I am accepting the user input,

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.