I am having difficulty finding the one best way to do something. I have three tables in mysql, this has to do with a gym app im building, one is for muscle exercises, one is for cardio exercises, the other is to house users results from each workout daily. Every day a workout is created based on 0 to 1 cardio exercises and 0 – however many muscle exercises the personal trainer decided. At the end of the workout the user puts their results for each exercise into a form and submits it. results are just a text field. I have a database that creates a row for every individual result that consists of
username,exercise type (muscle,cardio),exercise name, exercise result, date
so an example would be
John,muscle,bench press, 225lb max out, 2012-08-21
John,cardio,rowing,12 miles, 2012-08-21
I then want to take this info and display it in a standard table per the date chosen. So there are multiple users per date and each user can have multiple answers. The headers would be
username,cardio, muscle 1, muscle 2 ect.. ( shows as many as their are for that day )
then the results going down and filling in the table.
Aside from making dozens of select calls I am trying to figure out a way to do this. I am going thinking of trying to create some sort or array and use that. Any ideas?
I’d go with the array. The problem is in dispatching the muscle/cardio results.
To format in HTML and get the headers, let’s say we have first the cardio, then the muscle.
So you SELECT all rows of that date, ordering by username and cardio/muscle.
Then:
Now you have something like:
To format this in HTML, we have saved the maximum number of cardio of any user, and the maximum number of muscle. So a table of 1 + MaxC + MaxM columns will hold all users, ordered:
And to build it: