Php 分两列列出

Php 分两列列出,php,mysql,Php,Mysql,我有一个名字列表,我想把它们分成两列,像这样。 另外,如果第一列在第二列中继续,我想显示第一个字母和这个(续…) 这是现在的代码,但它没有在第二列显示C(续…) $alphabet = null; while($row1 = mysql_fetch_array($locals)) { if($alphabet != substs($row1['RSTOWN'],0,1)) { echo strtoupper(substr($row1['RSTOWN'],0,1)); $alphabet = su

我有一个名字列表,我想把它们分成两列,像这样。 另外,如果第一列在第二列中继续,我想显示第一个字母和这个(续…)

这是现在的代码,但它没有在第二列显示C(续…)

$alphabet = null;
while($row1 = mysql_fetch_array($locals)) {
if($alphabet != substs($row1['RSTOWN'],0,1)) {
echo strtoupper(substr($row1['RSTOWN'],0,1));
$alphabet = substr($row1['RSTOWN'],0,1);
}
echo '<li class="forward">
<a href="townpubs.php?RSTOWN='.$row1['RSTOWN'].'" rel="external">'
.$row1['RSTOWN'].
'<small class="listcounter">'.$row1['PubCount'].'</small>
</a>
</li>';
$alphabet=null;
while($row1=mysql\u fetch\u数组($locals)){
if($alphabet!=substs($row1['RSTOWN'],0,1)){
echo strtoupper(substr($row1['RSTOWN'],0,1));
$alphabet=substr($row1['RSTOWN'],0,1);
}
echo'
  • ';
    选择名称,说名称数=n,计算一半n=n/2

    存储在数组中,如果使用索引halfn+1存储名称

    检查上一个条目是否有相同的字母,如果有,在列表中存储一个“continued…”

    将列表从1打印到截断(列表中的入口数+1)/2以考虑奇数个条目


    在每行print[i]和[i+halfn]

    中,我不会对您自己的代码进行示例。但我将解释这些方法。您只需对它们实现sql即可

    现场示例:

    代码的完整版本:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>List in 2 columns - Kalle H. Väravas</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            html, body {margin: 0px; padding: 0px;}
            .container {width: 200px; float: left;}
        </style>
    </head>
    <body>
    <?php
    
    $countries = array(
        'Afghanistan',
        'Africa',
        'Albania',
        'Algeria',
        'American Samoa',
        'Bahamas, The',
        'Bahrain',
        'Bangladesh',
        'Barbados',
        'Bouvet Island',
        'Brazil',
        'Bulgaria',
        'Cambodia',
        'Cameroon',
        'Canada',
        'Cape Verde',
        'Caribbean',
        'Chad',
        'Chile',
        'China',
        'Christmas Island',
        'Colombia',
        'Comoros',
        'Congo',
        'Cook Islands',
        'Costa Rica',
        'Cote D\'Ivoire',
        'Croatia',
        'Denmark',
        'Djibouti',
        'Dominica'
    );
    
    $countries_count = count($countries);
    $breaking_point = round($countries_count / 2);
    $foreach_counter = 0;
    $current_letter = '';
    
    echo '<div class="container">';
    foreach ($countries as $country) {
        $foreach_counter++;
        if ($country[0] != $current_letter) {
            echo '<b>' . ($current_letter = $country[0]) . '</b><br />';
        }
        echo $country . '<br />';
        if ($foreach_counter == $breaking_point) {
            echo '</div><div class="container">';
        }
    }
    echo '</div>';
    
    ?>
    </body>
    </html>
    
    
    分两列列出-Kalle H.Väravas
    html,正文{margin:0px;padding:0px;}
    .container{width:200px;float:left;}
    
    捷克共和国为何缺失?:-)好吧,说真的,我怀疑这是个问题……如果你是程序员,为什么你不做你想要的程序?问题在哪里?
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>List in 2 columns - Kalle H. Väravas</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <style>
            html, body {margin: 0px; padding: 0px;}
            .container {width: 200px; float: left;}
        </style>
    </head>
    <body>
    <?php
    
    $countries = array(
        'Afghanistan',
        'Africa',
        'Albania',
        'Algeria',
        'American Samoa',
        'Bahamas, The',
        'Bahrain',
        'Bangladesh',
        'Barbados',
        'Bouvet Island',
        'Brazil',
        'Bulgaria',
        'Cambodia',
        'Cameroon',
        'Canada',
        'Cape Verde',
        'Caribbean',
        'Chad',
        'Chile',
        'China',
        'Christmas Island',
        'Colombia',
        'Comoros',
        'Congo',
        'Cook Islands',
        'Costa Rica',
        'Cote D\'Ivoire',
        'Croatia',
        'Denmark',
        'Djibouti',
        'Dominica'
    );
    
    $countries_count = count($countries);
    $breaking_point = round($countries_count / 2);
    $foreach_counter = 0;
    $current_letter = '';
    
    echo '<div class="container">';
    foreach ($countries as $country) {
        $foreach_counter++;
        if ($country[0] != $current_letter) {
            echo '<b>' . ($current_letter = $country[0]) . '</b><br />';
        }
        echo $country . '<br />';
        if ($foreach_counter == $breaking_point) {
            echo '</div><div class="container">';
        }
    }
    echo '</div>';
    
    ?>
    </body>
    </html>