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

  • SEARCH
  • Home
  • 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 8418763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:25:01+00:00 2026-06-10T02:25:01+00:00

I am having difficulty finding the one best way to do something. I have

  • 0

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?

  • 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-06-10T02:25:02+00:00Added an answer on June 10, 2026 at 2:25 am

    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:

    $users = array();
    $maxes = array('cardio' => 0, 'muscle' => 0);
    
    foreach($row = ...)
    {
        list($user, $com, $name, $result) = $row;
        if (!isset($users[$user]))
            $userData = array('cardio' => array(), 'muscle' => array());
        else
            $userData = $users[$user];
        $userData[$com][] = array($name, $result);
        if (count($userData[$com]) > $maxes[$com])
            $maxes[$com] = count($userData[$com]);
        $users[$user] = $userData;
    }
    

    Now you have something like:

    'John': {
         'cardio': [
            [ 'rowing', '12 miles' ],
            [ 'running', '2 miles' ],
         ],
         'muscle': [ ]
    },
    'Jack': {
         'cardio': [ ],
         'muscle': [ 'bench', '300lbs' ],
    }
    

    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:

    Name  Cardio 1    Cardio 2   Muscle 1
    
    John  Rowing      Running    -
          12 miles    2 miles
    Jack  -           -          Bench
                                 300lbs
    

    And to build it:

    // First the header
    print "<tr>";
    print "<th>Name</th>";
    for ($i = 0; $i < $maxes['cardio']; $i++)
        print "<th>Cardio " . ($i+1) . "</th>";
    for ($i = 0; $i < $maxes['muscle']; $i++)
        print "<th>Muscle ($i+1)</th>";
    print "</tr>";
    
    foreach($users as $user => $info)
    {
        print "<tr><td>$user</td>";
        foreach(array('cardio','muscle') as $key)
        {
            $data = $info[$key];
            for ($i = 0; $i < $maxes[$key]; $i++)
            {
                print "<td>";
                if (isset($data[$i]))
                {
                    list($name, $result) = $data[$i];
                    print "$name<br />$result";
                }
                else print '-';
                print "</td>";  
            } 
        }
        print "</tr>";
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently having difficulty finding a way of making my loops work. I have
I'm trying to create a Soundboard app, but I'm having difficulty finding a way
My apologies if this has already been answered - I'm having difficulty finding a
This seems simple enough, but I'm having difficulty finding an answer. I have a
Hilariously, I'm having incredible difficulty finding any half-good way to determine whether or not
I'm having difficulty finding support on this topic, because I know how to pass
Having difficulty finding relevant search results... Given this model: public abstract class A {
I am having difficulty finding space and time complexity for this code that i
This is probably an extremely basic question but I'm having difficulty finding an answer.
There is probably a really straightforward answer to this but I'm having difficulty finding

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.