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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:11:50+00:00 2026-06-07T06:11:50+00:00

I have a html table with a variable number of cells. For the sake

  • 0

I have a html table with a variable number of cells.
For the sake of this example i will say 20×20 (although it’s quite bigger).

This is generated via php and the dataset to populate the table has been pulled from mysql.
Each one of these cells has a numeric value, and it needs to specifically be placed where is is. So if cell A(10,15) has a value of 100, that 100 needs to specifically be on 10,15-
And while the table is being generated i have no way to analyze the positioning.

Now, many of these cells, have other adjacent cells with the same value. Either horizontally or vertically.

What i need to do is merge adjacent cells of a this table that have the same value.
This could be horizontal, vertical, or both, but still keeping it a rectangle- Nothing too funky.

For example if i have

0 1 1 1 0
2 2 5 0 4
5 5 5 1 4

i need to modify the colspan and/or rowspan based on value-
To be noted is that upon generation i can actually define classes or ids for each one
of these cells. Also during generation i can identify wether there will be more than one in a series in a row, but i have no way of knowing wether there will be one on the row below.

ps: i did do a bit a research and found this thread.
Complex table merging javascript & jquery algorithm

modified the jsfiddle example to affect both colspan and rowspan of the cell but it seems to flip out when it needs to merge more that two cells-

What could be a suggested approach on the matter?

Thank you in advance

  • 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-07T06:11:51+00:00Added an answer on June 7, 2026 at 6:11 am

    Do it in two passes (O(n2)), first traverse your array in the width and detect the number of adjacent cells (and set zero for a cell after the same one) :

    0(1) 1(3) 1(0) 1(0) 0(1)
    2(2) 2(0) 5(1) 0(1) 4(1)
    5(3) 5(0) 5(0) 1(1) 4(1)
    

    Then, traverse it vertically, and find cells where both numbers are the same (and the count > 0), you’ll get :

    0(1,1) 1(3,1) 1(0,0) 1(0,0) 0(1,1)
    2(2,1) 2(0,0) 5(1,0) 0(1,1) 4(1,2)
    5(3,1) 5(0,0) 5(0,0) 1(1,1) 4(1,0)
    

    Now, the first number of the pair is the colspan, the second is the rowspan. If one of the number is 0, don’t output it.

    0 1---- 0
    2-- 5 0 4
    5---- 1 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to render a complex table with variable number of columns. In this
I have an HTML table in my jsp page. This conains text fields and
I have a html table like this: Invoice# Due Date Balance Select 12345 12/25/2011
I have this html table: <table class=table-all> <tbody> <tr> <td>BISFENOLO</td> <td>Bisfenolo-AF 10/10</td> <td class=right>€
I have an HTML table like: <div> <table border=1> <thead> <tr class=example> <th> <span
I have to dynamically create a table with a variable number of columns, determined
I have a table with variable-width cells, and I want to give the browser
I have the following table (the number of the references is variable): Id |
I have dynamically created HTML table clicking on its TH will reload the table
I have some table rows <tr class=b_row> <td> <div class=cpt> <h2> <a href=/ref/ref/1.html>example</a> </h2>

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.