简体   繁体   中英

How to link data between tables in same mySQL database?

I'm a newbie at coding in general, I have a very basic understanding of OOP and hierarchies, but I'm trying to code a plugin for my service club's website in PHP and SQL, and it's very confusing (I've only tried bits of Java and HTML/CSS). The website database is going to need a number of tables, but for the sake of keeping my head on straight, I'm just going to talk about two: "member" and "events."

I want to keep member info, obviously, within the member table, but I also want to be able to link events (volunteering events) and their hours (the hours members earn from participating) to member id's. Object Member has hour_count and events_done, Object Event has duration and name. I want Members to summate all Event.duration's into hour_count, and to list all Event.name's in a string under events_done. I think it's a many-to-many relationship, but I don't know if this is possible.

I did some research on other posts here, but a lot of the content seems a level above my paygrade. Would anyone be able to sort of Explain Like I'm 5 for me?

Basically: Is what I'm asking possible, and if so, what is a safe and simple way for a newbie like me to go about connecting the data?

Apologies if something is unclear, I'll try to clarify as much as possible, thank you!

this is your tables:

`members`
hour_count|events_done

`event`
|duration| name|

and for the query :

insert into members(hour_count,events_done) select duration,name from `event`;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM