-2

任何人都知道为什么我$result在页脚而不是正文中回声?是html可能是div问题还是PHP?

这是与我所拥有的类似的东西:

    <?php
      // 1. Create a database connection
      $dbhost = "localhost";
      $dbuser = "tester";
      $dbpass = "12345";
      $dbname = "practice";
      $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
      // Test if connection occurred.
      if(mysqli_connect_errno()) {
        die("Database connection failed: " . 
             mysqli_connect_error() . 
             " (" . mysqli_connect_errno() . ")"
        );
      }
    ?>

    <?php
    // 2. Perform database query
    $SQLstring = "SELECT *FROM user ORDER BY username";


    // Test if there was a query error
    $QueryResult = @mysqli_query($connection, $SQLstring)
    Or die("<p>Unable to execute query.</p>"
    . "<p>Error code " . mysqli_errno($connection)
    . ": " . mysqli_error($connection)) . "</p>";

    ?>

    <!DOCTYPE>
    <html>
    <head>
    </head>
    <body>
    <?php   
    //3. uses the mysqli_assoc() to print table
    echo "<table>";
    echo "<tr><th>Name</th><th>Address</th><th bgcolor='#0099FF'   
            align='left'>City</th><th bgcolor='#0099FF' align='left'>State</th></tr>";                  
    $num_results = $QueryResult->num_rows;

    for ($i=0; $i <$num_results; $i++) {
    // 3. Use returned data (if any)
    $Row = mysqli_fetch_assoc($QueryResult);  //associative array

    // output data from each row

    echo "<tr><td>{$Row['username']}</td>";
    echo "<td>{$Row['address']}</td>";
    echo "<td>{$Row['city']}</td>";
    echo "<td>{$Row['state']}</td>";
    </tr>";
    }

    // 4. Release returned data - close query
    mysqli_free_result($QueryResult);                           
    ?>
    </body>
    </html>

    <?php
      // 5. Close database connection
      mysqli_close($connection);
    ?>

有任何想法吗?表格打印得很好,没问题,只是不在网站上的正确位置

4

2 回答 2

1
 echo "<td>{$Row['city']}</td>";
    echo "<td>{$Row['state']}</td>";
    </tr>"; //You got an error here!
    }

我想你忘了回应这条线。

于 2013-07-21T07:06:19.950 回答
0

你应该得到解析错误,但我不能指出

试着改变这行

 // output data from each row

echo "<tr><td>{$Row['username']}</td>";
echo "<td>{$Row['address']}</td>";
echo "<td>{$Row['city']}</td>";
echo "<td>{$Row['state']}</td>";
echo "</tr>";
}
于 2013-07-21T07:10:24.237 回答