Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
使用for循环创建PHP表_Php_For Loop_Html Table - Fatal编程技术网

使用for循环创建PHP表

使用for循环创建PHP表,php,for-loop,html-table,Php,For Loop,Html Table,我想将这个html表转换为带有for循环的PHP表, 第一行和第一列应为空 <table border="1"> <thead> <tr> <th></th> <th>a</th> <th>b</th> <th>c</th> </tr> </thead> <

我想将这个html表转换为带有for循环的PHP表, 第一行和第一列应为空

<table border="1">
<thead>
    <tr>
        <th></th>
        <th>a</th>
        <th>b</th>
        <th>c</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>1</td>
        <td>a1</td>
        <td>b1</td>
        <td>c1</td>
    </tr>
    <tr>
        <td>2</td>
        <td>a2</td>
        <td>b2</td>
        <td>c2</td>
    </tr>

</tbody>
</table>

A.
B
C
1.
a1
b1
c1
2.
a2
b2
c2
这就是我迄今为止所尝试的:

 $Rows = 2; 
$Cols = 3; 
echo '<table class="table">';
echo '<thead>;
<tr>
<td></td>';
    for($i=1;$i<=$Rows;$i++)
    { 

        for($j=1;$j<=$Cols;$j++)
        {
            echo '<td>' . "a ".$i .'</td>'; 
            echo '</tr>';

            echo '<tr>';
            echo '<td>' . "b ".$j. '</td>'; 
            echo '</tr>';
        }
        echo '</thead>';
    }
    echo '</table>';
$Rows=2;
$Cols=3;
回声';
回声';
';
对于($i=1;$i请尝试以下代码

<table border="1">
    <thead>
        <tr>
            <th></th>
            <th>a</th>
            <th>b</th>
            <th>c</th>
        </tr>
    </thead>
    <tbody>
        <?php 
        for($i=1;$i<=2;$i++)
        {
        ?>
        <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo "a".$i; ?></td>
            <td><?php echo "b".$i; ?></td>
            <td><?php echo "c".$i; ?></td>
        </tr>
        <?php
        }
        ?>
    </tbody>
    </table>

A.
B
C
试试这种方法

<table border="1">
<thead>
    <tr>
        <th></th>
        <th>a</th>
        <th>b</th>
        <th>c</th>
    </tr>
</thead>
<tbody>
    <?php 
    $i=1;
    $query=mysql_query("select * from table");
    $row=mysql_fetch_array($query);
    foreach($row as $r)
    {
    ?>
    <tr>
        <td><?php echo $i++; ?></td>
        <td><?php echo $r['field1']; ?></td>
        <td><?php echo $r['field2']; ?></td>
        <td><?php echo $r['field3']; ?></td>
    </tr>
    <?php
    }
    ?>
</tbody>
</table>

A.
B
C

第一行和第二列应该是空的
->请解释。同时展示您迄今为止所做的代码工作?我的意思是,第一行和第二列实际上是一个空白框,没有任何值,谢谢,但它只是一个标准html表,没有sql