2012-12-03 50 views
0

這是生成列表和查詢數據庫的PHP代碼,我已經有一些CSS,但我想拆分列表中的6列,16行,每行,並在結尾處添加更多...鏈接我有一個非常長的934條目列表,並希望顯示它在一個6多欄菜單

<?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

爲什麼在數據重複兩次? – cimmanon

回答

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 
} 
相關問題