PHP에서 Datalist (ASP.NET) 기능을 구현하는 방법은 무엇입니까?
문제
아래와 같이 두 열로 데이터를 표시하고 싶습니다.
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 Easy, Datalist가 몇 가지 설정을 만들고 데이터 소스를 제공하면이를 렌더링 할 것입니다.
그러나 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는 그렇지 않습니다.
당신의 질문에 대답합니까?
제휴하지 않습니다 StackOverflow