我有一个非常长的934条目列表,并希望在6多列菜单中显示它

时间:2012-12-03 00:09:03

标签: php css

这是生成列表并查询db的php代码,我已经有了一些css,但我想将列表分成6列,每行16行,并在末尾添加更多...链接

<?php

$show_manufacturers= true;

// for large lists of manufacturers uncomment this section

/*  if (($_GET['main_page']==FILENAME_DEFAULT and ($_GET['cPath'] == '' or    $_GET['cPath'] == 0)) or  ($request_type == 'SSL')) {
$show_manufacturers= false;
} else {
$show_manufacturers= true;
}
*/

//设置为true以显示制造商图像而不是名称

define('DISPLAY_MANUFACTURERS_IMAGES',false);
if ($show_manufacturers) {

// only check products if requested - this may slow down the processing of the    manufacturers sidebox
if (PRODUCTS_MANUFACTURERS_STATUS == '1') {
$manufacturer_sidebox_query = "select distinct m.manufacturers_id, m.manufacturers_name, m.manufacturers_image
                        from " . TABLE_MANUFACTURERS . " m
                        left join " . TABLE_PRODUCTS . " p on m.manufacturers_id = p.manufacturers_id
                        where m.manufacturers_id = p.manufacturers_id and p.products_status= 1
                        order by manufacturers_name";
} else {
$manufacturer_sidebox_query = "select m.manufacturers_id, m.manufacturers_name, m.manufacturers_image
                        from " . TABLE_MANUFACTURERS . " m
                        order by manufacturers_name";
}

$manufacturer_sidebox = $db->Execute($manufacturer_sidebox_query);

if ($manufacturer_sidebox->RecordCount()>0) {
$number_of_rows = $manufacturer_sidebox->RecordCount()+1;

//显示列表

$manufacturer_sidebox_array = array();
//      kuroi: commented out to avoid starting list with text scrolling list    entries such as "reset" and "please select"
//    if (!isset($_GET['manufacturers_id']) || $_GET['manufacturers_id'] == '' ) {
//      $manufacturer_sidebox_array[] = array('id' => '', 'text' => PULL_DOWN_ALL);
//    } else {
//      $manufacturer_sidebox_array[] = array('id' => '', 'text' =>  PULL_DOWN_MANUFACTURERS);
//    }

while (!$manufacturer_sidebox->EOF) {
  $manufacturer_sidebox_name = ((strlen($manufacturer_sidebox- >fields['manufacturers_name']) > MAX_DISPLAY_MANUFACTURER_NAME_LEN) ?  substr($manufacturer_sidebox->fields['manufacturers_name'], 0,  MAX_DISPLAY_MANUFACTURER_NAME_LEN) . '..' : $manufacturer_sidebox- >fields['manufacturers_name']);
  $manufacturer_sidebox_image = $manufacturer_sidebox->fields['manufacturers_image'];
  $manufacturer_sidebox_array[] =
    array('id' => $manufacturer_sidebox->fields['manufacturers_id'],
          'text' => DISPLAY_MANUFACTURERS_IMAGES ?
            zen_image(DIR_WS_IMAGES . $manufacturer_sidebox_image,     $manufacturer_sidebox_name) :
            $manufacturer_sidebox_name);
  $manufacturer_sidebox->MoveNext();
}

}

} // $ show_manufacturers这是我需要进行更改的地方

for ($i=0;$i<sizeof($manufacturer_sidebox_array);$i++) {
      $content = '';
  $content .= '<li ><a class="hide" href="' . zen_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $manufacturer_sidebox_array[$i]['id']) . '">';
  $content .= $manufacturer_sidebox_array[$i]['text'];
  $content .= '</a></li>' . "\n";
  echo $content;
}
?>

1 个答案:

答案 0 :(得分:0)

如果您正在寻找纯CSS解决方案,您有两个选择:

使用CSS3 columns属性,但它仅适用于现代浏览器(有些需要带前缀的版本)。无论如何,你都可以保证获得6列。您的元素将像报纸文章一样呈现(从上到下阅读)。

http://caniuse.com/#feat=multicolumn

http://jsfiddle.net/funag/

使用浮动。 Float已经永远存在,但是如果您正在查看可能会自动换行的内容,则可能需要花费更多精力来排列特定方式。好的一面是,如果你的设备太窄而不能支持6列,那么它将优雅地包裹到许多列,这对于该宽度是有意义的而无需滚动。您的元素将呈现为段落(从左到右阅读)。

http://jsfiddle.net/funag/2/

如果你想通过PHP分解你的元素,你想要的是模数运算符:

if ($i % 6 == 0) {
    // insert html tags to force a break
}