是否可以按列用值填充表格
Is it possible to fill a table with values in column wise?
是否可以按列用值填充表。例如
<?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
我提出了一个条件,即不更改表格中的值。(将echo从$j.$i更改为$i.$j会带来这种外观,但我想按列填充数据)。它是如何成为可能的?
在不深入了解JS问题的细节的情况下,您的PHP是完全错误的(如果您查看了PHP生成的HTML,您应该能够看到这一点):
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>';
我相信这是:
$variable1="xyz";
for($i=1; $i<=$pages; $i++)
{
echo '<li value"'.$i.'" id="'.$i.'" onclick=loadXmlDoc("'.$i,$variable.'")>'.$i.'</li>';<br>
}
需要:
$variable1="xyz";
for($i=1; $i<=$pages; $i++)
{
echo '<li value="'.$i.'" id="'.$i.'" onclick=loadXmlDoc('''.$i.''','''.$variable.''')>'.$i.'</li>';<br>
}
以下是你真正的做法,老派风格,完整评论以供解释。
<?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> </td>"; //Add some extra space between columns
}else{
//write empty cells if the data set doesn't completely fill the last column
echo "<td> </td>";
echo "<td> </td>";
echo "<td> </td>";
}
if($number_of_columns == $column_count){
echo "</tr>";
$row_count++;
$column_count=0;
}
}
//close the table element
echo "</table>";
?>
相关文章:
- 动态生成的表格 - 使用数组填充TD值
- 使用Javascript和html从Google电子表格中填充html代码
- 谷歌应用程序-不;t在使用调试运行脚本期间填充电子表格单元格
- 当下拉列表中的项目发生更改时填充表格 剃刀 mvc3
- 创建电子表格并用特定数据填充它们
- 如何用背景色动态填充表格单元格
- 使用 .click 函数在表格中显示元素.如何区分使用循环填充的表中的元素
- 根据两个下拉菜单中的值填充并显示html表格
- 是否可以按列用值填充表格
- 填充在“;显示:表格单元格”;
- 填充导航栏的方法-表格/CSS/JS
- 使用Google电子表格中的值数组填充jQuery自动完成列表
- 谷歌脚本'GetValue'不会't读取填充有'查询'在电子表格中
- 根据所选日期从客户端填充表格
- 用JavaScript填充表格
- 用PHP和AJAX从下拉选择中填充表格
- 我可以让一个输入元素填充表格列的宽度吗?
- 在django模板中使用knockout.js填充表格
- 通过谷歌应用程序脚本的颜色填充电子表格中的谷歌日历事件
- 表格单元格中预填充的文本显示为“未定义”.当在JS中添加HTML标签时