将MySQL输出写入变量时的“数组到字符串转换”

时间:2014-02-20 13:23:34

标签: php html mysql

我正在尝试将MySQL select的输出写入变量。问题是我得到错误“Array to String conversion”。

    $user = mysql_query("select username from user");
echo "<table border='1'>";
if (isset($_POST['winneron'])) {
    echo "<tr>";
    while ($printuser = mysql_fetch_array($user)) {
        echo "<th align='center'>". $printuser['username'] . "</th>";
    }
    echo "</tr>";
    $user = mysql_query("select username from user");
    while ($printuser = mysql_fetch_array($user)) {
        $games = mysql_query("SELECT s.spielid, date, team1, team2, sieger, wettid, u.userid, w.spielid, team 
                              FROM user u, spiele s, wette w 
                              WHERE u.userid = w.userid 
                              AND u.username = '$printuser' 
                              AND w.spielid = s.spielid"); <-- Error line
        while ($printgames = mysql_fetch_array($games)) {
            if ( $printgames['sieger'] == $printgames['team1'] ) {
                echo "<tr><td align='center'><b>". strtoupper($printgames['sieger']) . "</b></td></tr>";    
            }
            else { 
                echo "<tr><td align='center'>". strtoupper($printgames['sieger']) . "</td></tr>"; 
            }
        }
    }
}

2 个答案:

答案 0 :(得分:2)

$printuser是一个数组,你就像字符串

一样使用它

答案 1 :(得分:2)

AND u.username = '$printuser'将其替换为AND u.username = '".$printuser['username']."'