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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:36:40+00:00 2026-05-27T18:36:40+00:00

I have a question that relates to setting up the third table ( Repair_Parts

  • 0

I have a question that relates to setting up the third table (Repair_Parts table) with the following structure:

Part Table

Part_id (INT, unsigned, autoincrement) – primary key

Part_name (VARCHAR(50)) – unique

Part_descrip (TEXT)

Repair Table

Repair_id (INT, unsigned, autoincrement) – primary key

Repair_name (VARCHAR(50)) – unique

Repair_descrip (TEXT)

Repair_Parts Table

Repair_id (Foreign key – relates to Repair Table’s Repair_id field)

Part_id (Foreign key – relates to Part Table’s Part_id field)

Repair_Part_Item# – numbering based on the number of Part_id field entries related to a particular Repair_id (used to store data about the parts associated with a repair) – I want this field to start numbering with “1” for each different repair_id.

Question

For example, lets say a php program allows a user to create directions on how to do an automotive repair. The user is indicates that the repair is “Check Battery” (which inserts data into the Repair table under the Repair_name field (VARCHAR(50)) and a short description of the repair (which inserts data into the Repair table under the Repair_descrip field (TEXT)). The user is also able to specify the particular parts involved in the “Check Battery” repair, which may be one or many, but in this case it is only 2 different parts, an “Alternator” and “Battery”. In a different entry a user specifies three parts for a different repair.

How would one go about creating this Repair_Parts table in phpMyAdmin or MySQL so that the database keeps track of the particular Parts necessary for the Repair? What Engine should be used? MyISAM or INNODB?

From what I’ve read about normalization of databases, I seem to have the correct way to structure my tables, but I can’t figure out how to make the Repair_Part_Item# field to store data the way I want. Specifically, assuming I have broken out my tables and their fields in an acceptable manner, how would I get the Repair_Part_Item# field to start numbering at 1 for each different Repair_id field entry, and to count up for each row with the same Repair_id with a different Part_id (and not allowing duplicate rows with the same Repair_id and Part_id)?

From what I’ve read about normalization this seems to be the correct way to structure my tables, but I can’t figure out how to do make the Repair_Part_Item# field work correctly.

I’m a relative newbie to MySQL and PHP, and am just trying to set up the databases before getting into the PHP side of the equation.

  • 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-27T18:36:40+00:00Added an answer on May 27, 2026 at 6:36 pm

    If I understood correctly, what you want is to have certain field that generates a sequence starting from 1, based on current Repair_id. This feature is best achieved by using a feature of MyISAM engine where you create a compound primary key ((Repair_id, id) with id being auto_increment) – however, MyISAM tables silently ignore foreign key relations so there will be no cascading deletes or updates. InnoDB supports foreign key constraints, but it doesn’t support the auto_increment generation in the same fashion as MyISAM does. The best thing you can do is create a trigger that will generate a sequential number incremented by 1 based on current Repair_id.

    DELIMITER $$
    
    CREATE TRIGGER `your_trigger_name` AFTER INSERT ON `your_table_name` 
    FOR EACH ROW BEGIN 
    
    SET new.Repair_Part_Item = (SELECT IF(ISNULL(Repair_Pair_Item, 1, MAX(Repair_Part_Item) + 1) FROM your_table_name WHERE Repair_id = new.Repair_id);
    
    END 
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
This question may not directly relate to programming. I have noticed that the technology
Question: I have a question that is apparently not answered by this already-asked Bash
I have a question that may be quite naive, but I feel the need
I have a question that I just don't feel like I've found a satisfactory
I have a question that I'm ashamed to ask, but I'm going to have
I have a question that may sound odd, but being somewhat of a newbie,
I have a question that can I use AS400ConnectionPool in Spring if then pls
I have a question that's somewhat of an extension of this thread . I
I have a simple question that I am posing mostly for my curiousity. What

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.