كيفية تنفيذ Datalist على (asp.net) النوع من الوظائف في PHP؟

StackOverflow https://stackoverflow.com/questions/1082084

  •  22-08-2019
  •  | 
  •  

سؤال

وأريد أن عرض البيانات في عمودين على النحو التالي

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 سهلة، مجرد الحصول على Datalist على جعل بعض الإعدادات وإعطاء مصدر البيانات إليها، وسوف تجعل من ذلك بالنسبة لك.

ولكن في PHP كيفية عرض هذا النوع من القائمة، يمكن لأي شخص أن تعطيني بعض التعليمات البرمجية لهذا؟

والشكر

هل كانت مفيدة؟

المحلول

وأنا افترض أنك تريد رسم الجدول أتش تي أم أل .. والتي من السهل جدا للتعامل مع تخطيط هتمل ورقم العمود المتغير. هنا هو رمز عينة من شأنها أن تفعل بالضبط ما تحتاجه ..

        /* 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