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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:29:14+00:00 2026-06-15T18:29:14+00:00

From a database I’m pulling a kind of timeline of Div’s with a certain

  • 0

From a database I’m pulling a kind of timeline of Div’s with a certain starting point and certain end point. Some of them overlap, some of them can be fitted next to each other.
from Database

Ultimately I want to slide them together so that it’s as compact as possible like this:
what we want to accomplish

I’m doubting how to approach this challenge: through a server side (php) script or with some javascript floating script thingy. Or off course a completely different approach

Could some one push me in the right direction?

Edit::
It’s important, as it’s a timeline, that the horizontal position of the div’s remain the same. So floating all the divs to the left or inline-block them is no option 🙂

My database setup:

id | name | start | end  
1  | a    | 2     | 7  
2  | b    | 5     | 10  
etc
  • 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-15T18:29:15+00:00Added an answer on June 15, 2026 at 6:29 pm

    your question sounds very naive but it is actually include some complex elements if needed to be resolved in the most OPTIMISED way.

    the quick answer of what I probably would do to generate your display –

    1. use the provided function that adds the row number to your table
    2. use your PHP code to generate a DIV container with
      style=”display:block” for every row

    3. inside the row generate appropriate size DIV (end-start * scale)
      with style=”display:inline-block; float:left; display:relative” and (EDIT:) add transparent DIV elements to compensate for the white spaces you need. (i.e. from 0 to start and from the end to the start of the next DIV)

    4. add the name field inside the DIV element

    use mySchema;
    drop procedure if exists tileItems;

    DELIMITER $$
    CREATE PROCEDURE tileItems ()
    BEGIN
    DECLARE p_id, p_start, p_end, p_row int;
    DECLARE done INT DEFAULT FALSE;
    DECLARE cur1 CURSOR FOR SELECT id, start, end FROM tasks order by start, id;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
    
    drop temporary table if exists tiles;
    
    create temporary table tiles (
    row int(11) NOT NULL,
    id int(11) NOT NULL,
    end int(11) NOT NULL
    );
    -- row field will indicates the row number the task should apear
    OPEN cur1;
    next_task: LOOP
    
    FETCH cur1 into p_id, p_start, p_end;
      IF (done) THEN
        LEAVE next_task;
      END IF;
    select min(row) from (select row, max(end) me from tiles t2 group by row) t1 
      where me < p_start
      into p_row;
    
    
    -- take care of row numbering  
    IF (p_row IS NULL) then
      select max(row) from tiles
        into p_row;
        IF (p_row IS NULL) then
          SET p_row = 0;
        END IF;
        SET p_row=p_row+1;
    END IF;
    
    insert into tiles (id, row, end)
      values (p_id,p_row,p_end);
    
    END LOOP;
    
    -- CLOSE cur1;
    -- here is your output, on the PHP/.Net code you should loop on the row 
    select tasks.*, tiles.row from tasks
    inner join tiles
     on tasks.id = tiles.id
    order by tiles.row, tasks.start;
    
    
    END $$
    DELIMITER ;   
    

    here is the table I used to check it –

    CREATE TABLE `tasks` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
      `start` int(11) NOT NULL,
      `end` int(11) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=11 ;
    
    
    INSERT INTO `tasks` (`id`, `name`, `start`, `end`) VALUES
    (1, 'A', 2, 6),
    (2, 'B', 5, 7),
    (3, 'C', 8, 10),
    (4, 'D', 1, 5),
    (5, 'E', 6, 7);
    

    few words regarding optimisation (one of my favourite subjects 🙂 –
    in this code there is no optimisation, it means that the task will be allocated to the first available line.
    in order to minimise the number of lines its possible (but will take some time) to create a function that uses Heuristic method to resolve this problem.

    output:

    id  name    start   end row
    4   D   1   5   1
    5   E   6   7   1
    3   C   8   10  1
    1   A   2   6   2
    2   B   5   7   3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I get text from database it can contain things like <h1> <div> etc...
My controller get datas from database model, and sends them to view. In view
I have some data from database coming out in a loop. Each of these
I save some values from database using this function (i've been replaced Vector, because
I am pulling data from database to show it with PHP in table. How
Dropdownlist read its values from database and show them. I want when page loaded
I'm getting content from database: $data=some markup <pre> <code> some code </code> </pre> some
What makes repository different from database, filesystem or any other kind of storage? How
I am reading from database with some text in Hebrew and trying to json_encode
I'm pulling records from database, and I have a filed called content_fr the _fr

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.