I apologize if there are similar questions ... I could not find them! What I would like to do is select several rows in the database and then extract them, but repeat them in groups based on unique rows. Let me explain with an example (I briefly omitted some things):
I have a request to select:
SELECT
e.exercisename ExerciseName,
eh.reps Reps,
eh.weight Weight
FROM workouts w
JOIN users u ON w.userid = u.id
JOIN workouts_history wh ON w.id = wh.workoutid
JOIN exercises e ON wh.exerciseid = e.id
JOIN exercises_history eh ON wh.id = eh.workouts_historyid
Right now, this gives me a table based on this, while:
while($workoutrowridge = $workoutresultridge->fetch_assoc()) {
$workoutoutputridge .= '<tr>';
$workoutoutputridge .= '<td>'.$workoutrowridge['ExerciseName'].'</td>';
$workoutoutputridge .= '<td>'.$workoutrowridge['Reps'].'</td>';
$workoutoutputridge .= '<td>'.$workoutrowridge['Weight'].'</td>';
$workoutoutputridge .= '</tr>';
}
as follows:
Exercise | Reps | Weight
---------------------------
Squats | 8 | 135
Squats | 8 | 225
Squats | 6 | 315
Squats | 2 | 405
Squats | 1 | 485
Bench (DB) | 8 | 60
Bench (DB) | 6 | 80
Bench (DB) | 4 | 90
Bench (DB) | 2 | 95
Pullup | 4 | 0
Pullup | 3 | 25
Pullup | 1 | 45
Pullup | 1 | 70
What I would like to do is make a new table appear for each unique "ExerciseName" (for example). A workout can only have 1 exercise, or it can be 20, with a different number of sets for each of them, for example:
Exercise | Reps | Weight
---------------------------
Squats | 8 | 135
Squats | 8 | 225
Squats | 6 | 315
Squats | 2 | 405
Squats | 1 | 485
Exercise | Reps | Weight
---------------------------
Bench (DB) | 8 | 60
Bench (DB) | 6 | 80
Bench (DB) | 4 | 90
Bench (DB) | 2 | 95
, - foreach PHP ... . ?