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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:27:34+00:00 2026-06-08T17:27:34+00:00

I have the following problem: I’m storing a list of items in the database

  • 0

I have the following problem: I’m storing a list of items in the database and displaying them on a web page. I need to assign id or class to every single item on a web page. The most straightforward way would be to assign the same ids as they have in the database. Here is an example:

Database

ID  |  Name
----+-----------
1   |  Apple
2   |  Orange
3   |  Banana

HTML

<ul>
  <li id="1">Apple</li>
  <li id="2">Orange</li>
  <li id="3">Banana</li>
</ul>

The obvious problem is that HTML ids can’t start with numbers. So I thought of giving the ids a prefix, for example:

<ul>
  <li id="f1">Apple</li>
  <li id="f2">Orange</li>
  <li id="f3">Banana</li>
</ul>

But this creates inconsistency between HTML and database and makes working with the objects more complicated. To solve this I would have to add a new column to the database:

ID  |  Name     |  HTML_ID
----+-----------+---------
1   |  Apple    |  f1
2   |  Orange   |  f2
3   |  Banana   |  f3

That doesn’t seem to be ideal solution either as now I need to enter HTML_ID manually to the database every time I add a new item. And I need to make sure that HTML_ID is always unique.

I’m sure people come across this problem rather often when doing web development. I was wondering if there is a better way to handle this than in the example above.

  • 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-06-08T17:27:35+00:00Added an answer on June 8, 2026 at 5:27 pm

    Add the prefix on the fly before putting the id into the HTML, and remove the prefix before searching the database. When choosing between cleaner database and cleaner code, choose cleaner database.


    Storing the prefixed id the database:

    1. Wastes space in the table for what is essentially a redundant data. Larger data effectively means “smaller” cache.
    2. Since you want to search it, requires an index. This is an index in addition to the index on id which you can no longer use for the query, but is still necessary to enforce uniqueness. All things being equal, every additional index makes INSERT/UPDATE/DELETE slower and can be extra expensive if your table is clustered*. And also qualifies as “larger data”, making the cache “smaller”.

    If your DBMS supports appropriate mechanism**, you don’t actually need to physically store the field – the DBMS can calculate it on the fly for you, rendering the point (1) irrelevant.

    However, you still need to index it, so point (2) remains relevant.


    * Some DBMSes don’t even give you a choice for turning-off the clustering (MySQL/InnoDB).

    ** Such as calculated column that can be indexed or indexed VIEW.

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

Sidebar

Related Questions

We have following problem. Developers frequently need to make small changes to our web
i have following problem: I have a class Foo which encapsulates a web-api. the
Hi i have following Problem. I write a Mediawiki Extension where i need some
if have the following problem: I have a List which i am going through
I have following problem. In my view model I defined some list properties as
I have following problem. I have a team page like this example: http://www.social-markets.de/social-commerce-team.html small
I have the following problem in Java: I have a base class and a
I have following problem with JPQL: One Class has three fields: public class Message{
I have following problem statement. Export a C++ class in the dll (un-managed). Create
I have following problem to be solved in java: Implement class Alkio. Test with

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.