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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:04:46+00:00 2026-05-18T20:04:46+00:00

I am new to MYSQL and have a problem. Its related to php too

  • 0

I am new to MYSQL and have a problem. Its related to php too I guess.

I have a table,
ID,CODE,string1,string2,string3,string4,string5,string6,string7

now, each customer has a unique code. Each code can store a maximum of 7 strings in their “list”.
PROBLEM – if the customer adds a new item or items (important!) to their list and their list is already full, then the list should push out the oldest string and add the new strings to the end.

So say, string 1 to 7 are filled with text t1 to t7.
then customer wants to add new items t8 and t9, I need to delete t1 and t2, move everything down 2 spaces and add t8 where t6 was and t9 where t7 was (at the beginning). This is easy to do in java or normal programming, but how can I do this quickly and easily and efficiently in mysql/php code?

Is it possible? Is this the correct way to do things in mysql? Is there a better way? sorry

  • 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-18T20:04:46+00:00Added an answer on May 18, 2026 at 8:04 pm

    I think your problem is more related to your database schema.
    You could change (if you can) your db like this :

    User(id, code)
    List(id, user_id, date, value)
    

    Then, for your user (1, ‘xxx’), you add 7 values :

    INSERT INTO List (user_id, `date`, `value`) VALUES
    (1, NOW(), 1),
    (1, NOW(), 2),
    (1, NOW(), 3),
    (1, NOW(), 4),
    (1, NOW(), 5),
    (1, NOW(), 6),
    (1, NOW(), 7);
    

    And, following your description, if you add two new numbers (8, 9) :

    DELETE FROM List ORDER BY `date` DESC, id DESC LIMIT 2; // 2 is the quantity you'll add
    

    and then add the two new entries :

    INSERT INTO List (user_id, `date`, `value`) VALUES
    (1, NOW(), 8),
    (1, NOW(), 9);
    

    Now, suppose you have three customer :

    User(1, 'xxx') // customer n°1
    User(2, 'yyy') // customer n°2
    User(3, 'zzz') // customer n°3
    

    The difference would occur in the user_id column in the List table :
    (I reduce to 2 entry per user) :

    INSERT INTO List (user_id, `date`, `value`) VALUES
    (1, NOW(), 1),
    (1, NOW(), 2),
    (2, NOW(), 1), // look! I change the user_id
    (2, NOW(), 2),
    (3, NOW(), 1), // look! I change the user_id here too
    (3, NOW(), 2);
    

    Now suppose you want to have the list of the user 3, you do this request :

    SELECT value FROM List WHERE user_id = 3; // the id of the user you want to have his list
    

    This will return two rows : 1, 2

    You don’t have to create a table per user, you just have to add an extra column to identify which user belongs the data in the same table than others users.

    Hope this helps ! 🙂

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

Sidebar

Related Questions

I am new to MYSQL and have a problem. Its related to php too
I'm quite new to MySQL and I'm confused with one problem: I have one
I'm new to MySQL and PHP. I have two tables, one to hold all
I have a MYSQL-Table which stores scores. Every time a user improves a new
I have got a native join sub query problem in MySQL Entity. SQL code
I'm fairly new to using MSSQL and have run into a weird problem. Given
I am fairly new to MySQL and have a project in which I need
I'm very new to MySQL and I have a stored procedure that I'd like
So I have this JS form that creates a new record ( MySQL ,
I am new to MySQL, but I have used Oracle for some time. I

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.