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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:06:38+00:00 2026-05-12T12:06:38+00:00

I have a user that enters a piece of data into my database and

  • 0

I have a user that enters a piece of data into my database and titles it “Widget Title”. If he calls another item “Widget Title”, and another, and another, when he sees them in his widget list I’d like to show them like such:

  • Some Item
  • Widget Title
  • Some Other Item
  • Widget Title 2
  • Widget Title 3
  • Yet Another Item
  • Widget Title 4

Where each duplicate occurrence has its own appended incrementing id.

Would you do this on the way into the database or when you display the output for the list?

Can I have the algorithm?

  • 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-12T12:06:38+00:00Added an answer on May 12, 2026 at 12:06 pm

    I just whipped this up in PHP for use on output and it seems to work well. Would you do anything differently?

        $my_titles_array = array('Some Title',
                             'Widget Name',
                             'Widget Name',
                             'Some Other Title',
                             'Widget Name',
                             'Yet Another Title',
                             'Widget Name'
                             );
    
    $counted_values_array = array_count_values($my_titles_array);
    
    foreach ($my_titles_array as $title)
    {
        if($counted_values_array[$title] > 1)
        {
            $matches_array = array_keys($my_titles_array, $title);
            $i=1;
    
            foreach($matches_array as $match)
            {
                if($i != 1)
                {
                    $my_titles_array[$match] = $title. ' '. $i;
                }
                $i++;
            }
        }
    }
    
    echo highlight_string(print_r($my_titles_array,true),true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that allows me to enter a user into my database.
I have a string mystring that the user enters. I check that it is
I have a few textboxes that are not required. If the user enters nothing
I am have a piece of code that prompts for user input and works
I have created a piece of code that checks files for a user-submitted string
I have a requirement that a user is allowed only to enter string value
I would like to have a text field that a user can enter a
I have a main report that prompts the user to enter two parameters (@ORI
I have a batch file that requires the user to enter a file path.
I have a program that allows the user to enter a level number, and

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.