0

信息

我目前有一张桌子,图片如下,表格图像

问题

我使用ul&制作了这张表,li 这是代码

http://jsfiddle.net/8j2qe/1/

问题

将数据存储在图像中并轻松显示的最佳方法是什么?

请记住,每列只能有 1 个条目。

谢谢!任何问题都会尽快得到解答!

编辑

抱歉,我认为我最初的问题不够清楚。我要问的是,存储然后显示此类数据的最佳方式是什么。我想从我的数据库中显示数据以像在图像中一样显示。

我是否应该在我的数据库中为表中的每一列设置一列,然后根据它所在的列说 A、B、C 或 D,但是我将如何在提供的代码中使用 PHP 显示它?

我正在努力寻找解释这一点的好方法,我很抱歉。

4

1 回答 1

0

You can save the data in form like

{
"0": [5,4,8],
"1": [2,3],
..
}

where object key refer to row index, and array values refer to index of checked column, you can easily generate this object in javascript by looping through each 'ul' element saving it's index as row index then get index of 'li' element that's checked & push it in array.

Then you serialize it back to server as json, save that json in DB.

Getting it back in php, you will loop through each row printing 'ul' element , then loop to print 'li' element, ex:

for ($i=0; $i < count($data); $i++) {
    echo '<ul>';

      //printing 18 column as u have in image
      for ($j=0; $j < 18; $j++) {      
         if ( in_array($j, $data[$i]) ) {
             echo '<li>CHECKED</li>';
         }else{
             echo '<li></li>';
         }
      }

    echo '</ul>';
}

i think that's better than having table in db for each table u have.

finally providing context will greatly help in making a better answer, for ex: how table is generated , it's use, ...

于 2013-10-27T21:34:09.527 回答