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

  • Home
  • SEARCH
  • 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 8785481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:22:23+00:00 2026-06-13T21:22:23+00:00

I’m trying to come up with a database relation to keep track of purchased

  • 0

I’m trying to come up with a database relation to keep track of purchased items that will be used for look up afterwards–for example ebooks. Ignore the ellipses–they represent miscellaneous data such as timestamp, etc…

Here’s the table I have right now:

purchased:
transaction_id(int)(pk)(auto_inc) | username (varchar) | purchases (text) | ...

In this design, the column “purchases” is just a string of text that would contain the item_id of items purchased, separated by commas. Simplified example: “book1, book23, book5, book8”.

In a successful transaction, this query would insert the transaction data into the “purchased” table:

INSERT INTO purchased VALUES (null, username, purchases, ...)

From this point on, two things can happen:

  1. The user can lookup what ebooks they’ve purchased
  2. The user can make another purchase transaction.

If the user (theusername) wants to see their ebooks, the system performs a selection query e.g.

SELECT purchases FROM purchased WHERE username=theusername

which returns a string containing the item IDs.

One a sidenot, is it possible to get an php array of purchases without having to use extra php code, i.e. explode? Can you use something besides the data type “text” in SQL to store a list of items? If not, that’s okay.


Either way, here’s the main problem. Say the user makes another transaction–there will now be two rows in “purchased” that contains the user’s purchased items. That means that in this table, the user’s purchases are split into multiple rows.

Ideally, I want these purchases to all be in the same row. I can’t use an UPDATE statement because each purchase has it’s own unique transaction_id.

I was thinking that I could make another table that contains all purchases by a user

all_purchased:
username (pk) | purchases (text) | ...

and whenever the user makes another transaction, the “all_purchased” table would just update its purchases column with the item ID of any new ebooks.

But this table seems redundant because the selection query I mentioned would get the task done.

What would be the best way to structure the database relation(s)?

  • 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-13T21:22:25+00:00Added an answer on June 13, 2026 at 9:22 pm

    Considering that you are using relational database — in there any special reason not to use normalized tables? Here is just one possibility.

    enter image description here

    This one propagates keys; if you have an ORM of some kind that has trouble with composite keys, modify as in this example.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small

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.