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.
我试图从数据库结果中显示类别列表,因为列表将逐日增加,我如何分割li元素,以便它们水平和垂直对齐。
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
我尝试使用CSS,它适用于较小的结果,但很难平等地组织列表。示例:Flipkart按以下方式列出其类别
Any suggestions, Or any other simple way to handle large list of categories?
任何建议,或处理大类别列表的任何其他简单方法?
Thank you.
1 个解决方案
#1
0
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.
这是我为你写的一个小代码。 “breakafter”变量将定义何时创建UL。我想这就是你要找的东西。
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.
就Flipkart而言,我认为他们有一个CMS,他们分别管理每一列。由于生成的链接数量彼此不相等,因此通过编码很难管理这种灵活性。
Check this out, maybe exactly what you want. Also, I just printed the '$i' so that you know when the ul & li are generated.
看看这个,也许正是你想要的。另外,我刚刚打印了'$ i',以便您知道何时生成ul&li。
$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>';
}
}
#1
0
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.
这是我为你写的一个小代码。 “breakafter”变量将定义何时创建UL。我想这就是你要找的东西。
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.
就Flipkart而言,我认为他们有一个CMS,他们分别管理每一列。由于生成的链接数量彼此不相等,因此通过编码很难管理这种灵活性。
Check this out, maybe exactly what you want. Also, I just printed the '$i' so that you know when the ul & li are generated.
看看这个,也许正是你想要的。另外,我刚刚打印了'$ i',以便您知道何时生成ul&li。
$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>';
}
}