php垂直对齐,php – 垂直对齐div,但保持水平位置不变

你的问题听起来很幼稚,但它实际上包括一些复杂的元素,如果需要解决在最优惠的方式。

快速回答我可能会做什么来生成您的显示 –

>使用提供的函数将行号添加到表中

>使用您的PHP代码生成DIV容器

style =“display:block”

>里面的行生成适当的大小DIV(end-start * scale)

with style =“display:inline-block; float:left; display:relative”和(EDIT :)添加透明DIV元素以补偿所需的空格。 (即从0到开始,从结束到下一个DIV的开始)

>在DIV元素中添加名称字段

使用mySchema;

drop procedure如果存在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 ;

这里是我用来检查它的表 –

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);

几个词关于优化(我最喜欢的主题:) –

在这段代码中没有优化,这意味着任务会被分配到第一个可用的行。

为了最小化它的可能的行数(但将需要一些时间)创建一个使用Heuristic方法来解决这个问题的函数。

输出:

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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值