質問

私は

以下のように2つの列のデータを表示したいです
Entry 1                                 Entry 2
entry 1 description                     entry 2 description

Entry 3                                 Entry 4
entry 3 description                     entry 4 description

Entry 5                                 
entry 5 description                     

今asp.netでそのprestty簡単、ちょうど取得データリストは、いくつかの設定を行い、それにデータソースを提供し、それはあなたのためにそれをレンダリングします。

しかし、PHPでリストのこの種の表示方法を、誰も私に、このためのいくつかのコードを与えることができますか?

おかげ

役に立ちましたか?

解決

私はあなたがHTMLテーブルを描きたいとし... これは、HTMLレイアウト&変数の列数を処理するように簡単です。 ここにあなたが必要なものを正確に行いますサンプルコードがある..

        /* populate sample data */
    for($i=1; $i<10; $i++) {  $data_array[]=array('Entry '.$i,'entry '.$i.' description');  }

    /* how many columns */
    $column_number='3';

    /* html table start */
    ?><table border="1" cellspacing="5" cellpadding="5"><?php

    $recordcounter=1;  /* counts the records while they are in loop */
    foreach($data_array as $record) { 

        /* decide if there will be new Table row (<TR>) or not ... left of division by column number is the key */
        if($recordcounter%$column_number==1){ echo "<tr>"; }
        ?>          
            <td> 
                <?=$record[0]?> 
                <br />
                <?=$record[1]?>
            </td>
        <?php
        /* decide if there will be end of table row */
        if($recordcounter%$column_number==0){ echo "</tr>"; }
        $recordcounter++;  /* increment the counter */
    }

    if(($recordcounter%$column_number)!=1){ echo "</tr>"; }  

    ?></table><?php

他のヒント

私はあなたがHTML出力を構築する方法を求めていると仮定?

<?php $array = array('Item 1' => 'Description 1', 'Item 2' => 'Description 2'); ?>

<dl>
<?php foreach ($array as $item => $description) : ?>
    <dt><?php echo $item; ?></dt>
    <dd><?php echo $description; ?></dd>
<?php endforeach; ?>
</dl>

あなたが簡単に列を作るか、またはあなたが何を持っているために、フローティング、この使用してCSSのスタイルを設定することができます。

あなたは、フレームワークを使用している場合は、

それがこれを行うためのいくつかの並べ替えのヘルパーを含むことができますが、標準のPHPにはありません。

それは、あなたの質問に答えるのか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top