dongxiaoke2018 2014-01-29 06:07
浏览 49

如何在html和php中水平拆分大型动态List

I am trying to display a list of categories from a Database result, As the list will increase day by day how can i split the li elements so that they align themselves horizontally and vertically.

Here is my code snippet

<?php
$query="SELECT id,category FROM category`";
$res=mysql_query($query);
$count=mysql_num_rows($res);
while($data=mysql_fetch_array($res))
{
?>
<table>
<tr>
    <td>
        <li><a><?= $data['category']?></a></li>
    </td>
</tr>
</table>
<?php
}
?>

I tried using css, it worked for smaller results, but it became difficult to organize the list equally. Example: Flipkart lists their categories in the following way enter image description here

Any suggestions, Or any other simple way to handle large list of categories?

Thank you.

  • 写回答

1条回答 默认 最新

  • dongshi6710 2014-01-29 17:17
    关注

    Here is a small code i wrote for you write now. the "breakafter" variable will define when to create a UL. I think this is what you are looking for.

    As far as Flipkart goes, I think they have a CMS where they manage each column separately. Because the number of links that are generated are not equal to each other & this flexibility is very difficult to manage by coding.

    Check this out, maybe exactly what you want. Also, I just printed the '$i' so that you know when the ul & li are generated.

    $count  = mysql_num_rows($query);
    echo $count;
    $i = 0;
    $breakafter = 5;
    
    while($data=mysql_fetch_array($query)){ 
    $i++;
    if($i == 1){ 
    echo '<ul><li>'.$data['samplecode'].'-i is - '.$i.'</li>';
    
    } elseif ($i % $breakafter == 0) {
    
    echo' <li>'.$data['samplecode'].'-i is - '.$i.'</li></ul><ul>';
    
    
    } else {
    
    echo' <li>'.$data['samplecode'].'-i is - '.$i.'</li>';
    }
    
    
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题