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 3275112
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:06:33+00:00 2026-05-17T19:06:33+00:00

I have come unstuck on a relatively (almost) trivial problem. I have a row

  • 0

I have come unstuck on a relatively (almost) trivial problem. I have a row of data that I want to display in tabular form (HTML). For some reason (possibly long day [again] behind the computer), I am not coming up with any elegant solutions (algorithms) to do this.

I have presented some sample data, and how such data would be displayed in the table. I would be grateful for some ideas on algos to implement this.

The output table has rows labelled with the various scores and the indices are displayed at the bottom.

I would like to be able to have a variable determine the number of columns to print, before a new table is printed underneath – to prevent ridiculously long tables.

so I want to write a function with the following signature (ignoring data types):

function create_table_html_from_rows(datarows, max_cols_per_table)

Here is the sample data and mock output table presentation

Row data:

index, Score, amount
1, level 1, 12.24
3, level 4, 14.61
9, level 10, 42.35
15, level 2, -8.12


Scores
======

Level 1  12.24   
Level 2                       -8.12
Level 3
Level 4         14.61
.....
Level 10               42.35
----------------------------------------
         |  1  |  3  |  9   |   15       <- Index

Pseudocode should be sufficient, however, if you snippet is in a programming language, it is perharps worth pointing out that I will be implementing my algorithm in Python, however any snippets in any of the following languages would be fine:

Python, C, C++, PHP, C#

  • 1 1 Answer
  • 2 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-05-17T19:06:33+00:00Added an answer on May 17, 2026 at 7:06 pm

    I assumed you have Raw data stored similar to what I have below.
    Also, the level is non-unique.

    <?
        $rowData = array( 
            0=> array('index'=>1, 'Score'=>"level 1", 'amount'=>12.24), 
            1=> array('index'=>3, 'Score'=>"level 4", 'amount'=>14.61),
            2=> array('index'=>9, 'Score'=>"level 10", 'amount'=>42.35),
            3=> array('index'=>15, 'Score'=>"level 2", 'amount'=>-8.12),
            4=> array('index'=>12, 'Score'=>"level 10", 'amount'=>16.5)
            // example Raw Data with non-unique levels
        );
        $numOfScores = 15; // Predefined Score Level Max
        foreach($rowData as $c){
            $cols[] = $c['index']; //Create index row
            $score = str_replace("level ","",$c['Score']); // split the score so it is only numeric
            $levels[$score][] = $c; //create a 2-D array based on the level
        }
        echo "<table><tr><th colspan=".(sizeof($cols)+1).">Scores:</th></tr>";
        for($ii = 1; $ii < $numOfScores; $ii++){ // Go through the levels
            echo "<tr><td>Level ".$ii."</td>";
            for($i = 0; $i < sizeof($cols); $i++){
                echo "<td>";
                if(isset($levels[$ii])){ // If I have a level, let's print it in the right column
                    foreach($levels[$ii] as $lvl)
                        if($cols[$i] == $lvl['index']) echo $lvl['amount'];
                }
                echo "</td>";
            }
            echo "<tr>";
        }
        echo "<td>Index:</td>";
        foreach($cols as $c){
            echo "<td>$c</td>";
        }
        echo "</table>";
        ?>
    

    I get the following output:

    Scores:
    Level 1 12.24               
    Level 2             -8.12   
    Level 3                 
    Level 4     14.61           
    Level 5                 
    Level 6                 
    Level 7                 
    Level 8                 
    Level 9                 
    Level 10        42.35       16.5
    Level 11                    
    Level 12                    
    Level 13                    
    Level 14                    
    Index:  1   3   9   15  12
    

    It is tabbed correctly on my screen, probably won’t appear to be.

    As you can see, I added an extra row in your data to simulate a non-unique row. Should work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come accross the static HTML app for facebook pages that allows us
I have come to a problem, wich I have no idea how to solve.
I’m having fun with EF and have come unstuck. Originally I used the following
I have come across this rule in YSlow for performance improvement that says that
I have come across a case as described below, and want to understand how
I have come across a problem I cannot seem to solve. I have a
I have come accross something that at first view seems to be a bug
I've come unstuck this particular problem as I'm still fresh to NHibernate/FluentNHibernate. I will
Have come against an interesting problem and I'm stumped. Basically on one of our
I have come across an odd behaviour in NSKeyedUnarchiver. I archive a data, for

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.