In my database I have a table of "weeks" and a table of "workouts". I would like to achieve something like the following:
- Week 1
- workout 1 title
- workout 1 content
- workout 2 title
- workout 2 content
- workout 3......
- week 2
- workout 1 title
- workout 1 content
- workout 2 title
- workout 2 content
- workout 3......
- week 3.....
I've trying something like:
function get_weekly_content() {
$user_id = $this->session->userdata('id');
$weeks = $this->db->select('week_no')->where('user_id', $user_id)->get('weeks');
if($weeks->num_rows > 0) {
foreach($weeks->result() as $row) {
$week_no = $row->week_no;
$workouts = $this->db->where('user_id', $user_id)->where('week_no', $week_no)->get('workouts');
if($workouts->num_rows > 0) {
foreach($workouts as $workout) {
$workout_data[] = $workout;
}
}
$weekly_data[] = $workout_data;
}
return $weekly_data;
}
}
but maybe I have the wrong idea. I would then also need to display the data.
EDIT my question is, what would be the best way to achieve the above and get and array/object to loop through on a view page?
Thanks
$workout_data