Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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_Html - Fatal编程技术网

Php 表格是水平显示的,而不是垂直显示的

Php 表格是水平显示的,而不是垂直显示的,php,html,Php,Html,我试图用PHP和HTML创建一个表,该表从MySQL数据库获取数据。 问题是数据是水平显示的,而不是垂直显示的 if (isset($_POST['winneron'])) { echo "<tr>"; while ($printuser = mysql_fetch_array($user)) { echo "<th>". $printuser['username'] . "</th>"; } echo "<

我试图用PHP和HTML创建一个表,该表从MySQL数据库获取数据。 问题是数据是水平显示的,而不是垂直显示的

if (isset($_POST['winneron'])) {
    echo "<tr>";
    while ($printuser = mysql_fetch_array($user)) {
        echo "<th>". $printuser['username'] . "</th>";
    }
    echo "</tr>";
    while ($printgames = mysql_fetch_array($games)) {
        if ( $printgames ['winner'] == $printgames ['team1'] ) {
            echo "<td><b>". strtoupper($printgames ['winner']) . "</b></td>";   
        }
        else { 
            echo "<td>". strtoupper($printgames ['winner']) . "</td>"; 
        }
    }   
}

希望有人能帮助我。

如果你想让你的显示器垂直,那么你必须把每一条信息放在一个表格行中

在您的while$ausgabespiele=mysql\u fetch\u数组$spiele{}中没有,您在while中缺少TR

 if (isset($_POST['winneron'])) {
        echo "<tr>";
        while ($ausgabeuser = mysql_fetch_array($user)) {
            echo "<th>". $ausgabeuser['username'] . "</th>";
        }
        echo "</tr>";
        while ($ausgabespiele = mysql_fetch_array($spiele)) {
           echo "<tr>";
            if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
                echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; 
            }
            else { 
                echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; 
            }
           echo "</tr>";
        }   
    }

您必须在while循环中添加行标记

if (isset($_POST['winneron'])) {
    echo "<tr>";
    while ($ausgabeuser = mysql_fetch_array($user)) {
        echo "<th>". $ausgabeuser['username'] . "</th>";
    }
    echo "</tr>";
    while ($ausgabespiele = mysql_fetch_array($spiele)) {
        echo "<tr>";
        if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
            echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; 
        }
        else { 
            echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; 
        }
        echo "</tr>";
    }   
}

您忘记在循环中创建表行。要垂直显示,需要将表格单元格按行放置:

while ($ausgabespiele = mysql_fetch_array($spiele)) {
    echo "<tr>";
    if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {

        echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; 
    }
    else { 
        echo "<tr><td>". strtoupper($ausgabespiele['sieger']) . "</td></tr>"; 
    }
    echo "</tr>";
} 
试试这个-

if (isset($_POST['winneron'])) {
    $echo = "<tr>";
    while ($ausgabeuser = mysql_fetch_array($user)) {
        $echo .= "<th>". $ausgabeuser['username'] . "</th>";
    }
    $echo .= "</tr><tr>";
    while ($ausgabespiele = mysql_fetch_array($spiele)) {
        if ($ausgabespiele['sieger'] == $ausgabespiele['team1'])
            $echo .= "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; 
        else 
            $echo .= "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; 
    }
    $echo .= "</tr>";

    echo $echo;  
}

你能发布你当前显示数据的截图吗?我们很难理解上面的代码显示了什么;移动到其他{echo.strtoupper$ausgabespiele['sieger'];}之后,您会在一段时间内忘记。
if (isset($_POST['winneron'])) {
    $echo = "<tr>";
    while ($ausgabeuser = mysql_fetch_array($user)) {
        $echo .= "<th>". $ausgabeuser['username'] . "</th>";
    }
    $echo .= "</tr><tr>";
    while ($ausgabespiele = mysql_fetch_array($spiele)) {
        if ($ausgabespiele['sieger'] == $ausgabespiele['team1'])
            $echo .= "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>"; 
        else 
            $echo .= "<td>". strtoupper($ausgabespiele['sieger']) . "</td>"; 
    }
    $echo .= "</tr>";

    echo $echo;  
}