2013-08-07 2 views
-1

표를 값으로 채울 수 있습니까? 예를 들어열 단위로 값이있는 테이블을 채울 수 있습니까?

나는 테이블에 입력해야하는 값을 변경하지 않음으로써 조건 최대와 함께
<?php 
echo "<table>"; 
for ($j=0;$j<6;$j++) 
{ 
echo "<tr>"; 
for ($i=0;$i<6;$i++) 
{ 
echo "<td>".$j.$i."</td>"; 
} 
echo "</tr>"; 
} 
echo "</table>"; 
?> 

는 출력은

00 01 02 03 04 05 
10 11 12 13 14 15 
20 21 22 23 24 25 
30 31 32 33 34 35 
40 41 42 43 44 45 
50 51 52 53 54 55 

하게하지만 난

00 10 20 30 40 50 
01 11 21 31 41 51 
02 12 22 32 42 52 
03 13 23 33 43 53 
04 14 24 34 44 54 
05 15 25 35 45 55 

처럼 보이도록 테이블을 원했다 . ($ j. $ i에서 $ i. $ j로 에코를 변경하면 그 모습을 나타내지 만 데이터를 열 단위로 채우기를 원한다). 어떻게 가능합니까?

echo '<li value"'.$i.'" id="'.$i.'" onclick=loadXmlDoc("'.$i,$variable.'")>'.$i.'</li>';<br> 

뭔가해야한다 : 심지어 JS 문제의 세부 사항에 가지 않고

답변

0

, 당신의 PHP는 (당신이 당신의 PHP가 생성하는 HTML 보았다 경우에 당신이 볼 수 있어야 함) 완전히 잘못이다 이 같은 이상 :

$variable1="xyz"; 
for($i=1; $i<=$pages; $i++) 
{ 
    echo '<li value"'.$i.'" id="'.$i.'" onclick=loadXmlDoc("'.$i,$variable.'")>'.$i.'</li>';<br> 
} 

필요로 :

echo '<li value="'.$i.'" id="'.$i.'" onclick="loadXmlDoc(\''.$i.'\',\''.$variable.\''")>'.$i.'</li><br>'; 
0

다음은 완전히 설명하는 구식 스타일입니다.

<?php 
//NOTE: This excercise would be slightly easier if you just used php's DomDocument class because you wouldn't 
//need to waste some logic determining whether to open/close the table rows, but here it is just echoing 
//out some straight html 

//The example data 
$data_set = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); 
//at the very least, you'll need to know how many columns you want to format the data into... 
$number_of_columns = 5; 
//count the data items 
$number_of_data_items=count($data_set); 
//determine how many rows you'll need to display the data in the given number of columns 
$num_rows=ceil($number_of_data_items/$number_of_columns); 
//determine exactly how many cells it will take to display the data 
$num_cells=$num_rows*$number_of_columns; 

//now that we have enough info to output the table... 
//init some counters 
$row_count=0; 
$column_count=0; 
//open the table element 
echo "<table border='1' cellspacing='0' cellpadding='5'>"; 
for($i=0;$i<$num_cells;$i++){ 

    $column_count++; 
    $index = $row_count + ($num_rows * ($column_count-1)); 
    if($column_count==1){ 
     echo "<tr>"; 
    } 

    if( $index < $number_of_data_items){ 
     echo "<td>Item :".($index+1)."</td>"; //Display the number of the data item we are 
     echo "<td>".$data_set[$index]."</td>"; //Display the actual data item 
     echo "<td>&nbsp;&nbsp;</td>"; //Add some extra space between columns 
    }else{ 
     //write empty cells if the data set doesn't completely fill the last column 
     echo "<td>&nbsp;</td>"; 
     echo "<td>&nbsp;</td>";  
     echo "<td>&nbsp;&nbsp;</td>"; 
    } 
    if($number_of_columns == $column_count){ 
     echo "</tr>"; 
     $row_count++; 
     $column_count=0; 
    } 
} 
//close the table element 
echo "</table>"; 
?> 
관련 문제