Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否可以在表格中按列填写值?_Php_Javascript_Jquery_Html_Css - Fatal编程技术网

Php 是否可以在表格中按列填写值?

Php 是否可以在表格中按列填写值?,php,javascript,jquery,html,css,Php,Javascript,Jquery,Html,Css,是否可以按列方式用值填充表格。比如说 <?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 10 20 30 40 50 01

是否可以按列方式用值填充表格。比如说

<?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  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'
  • “.$i.

  • 应该是这样的:

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

  • ';
    我认为:

    $variable1="xyz";
    for($i=1; $i<=$pages; $i++)
    {   
        echo '<li value"'.$i.'" id="'.$i.'" onclick=loadXmlDoc("'.$i,$variable.'")>'.$i.'</li>';<br>
    }
    
    $variable1=“xyz”;
    
    对于($i=1;$i这是你真正的做法,老式风格,完整的评论以供解释

     <?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>";
    ?>
    
    
    
    $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>&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>";
    ?>