dsaj20411 2014-02-20 13:23
浏览 49
已采纳

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

I'm trying to write the output of a MySQL select into a variable. The problem is that i get the error "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条回答 默认 最新

  • doujingxi3356 2014-02-20 13:28
    关注

    AND u.username = '$printuser' replace it with AND u.username = '".$printuser['username']."'

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?