您的代码将起作用。如果重写像$host = "localhost";
$dbusername = "root"; // username
$dbpassword = "password"; // your password
$dbname = "test"; // dbname
//Create connection
$conn = new mysqli($host, $dbusername, $dbpassword, $dbname);
$sql = "SELECT * FROM fruit";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
echo "
- ";
if ($resultCheck > 0) {
while ($rows = mysqli_fetch_assoc($result)) {
//echo $row['username'] . "
";
echo "
A ".$rows["name"]." is ".$rows["color"]. "";}
} else {
echo "Fail";
}
echo "
";我用表格测试代码。请在您的代码中进行相应的更改。
一切顺利
Anes