gpt4 book ai didi

php - 显示除第 1 行以外的所有行

转载 作者:太空宇宙 更新时间:2023-11-03 10:38:15 24 4
gpt4 key购买 nike

当我从数据库 (MySQL) 中选择一些数据时,它会显示除第一行以外的所有行。如何解决?

代码

// Create connection
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, title, image, description, tekst, address, website, telephone, email, openinghours FROM ExperienceUtrecht";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "<table border='1'> <tr> <th>ID</th> <th>Title</th> <th>Image</th> <th>Description</th> <th>Tekst</th> <th>Address</th> <th>Website</th> <th>Telephone</th> <th>Email</th> <th>Opening Hours</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['image'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['tekst'] . "</td>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['website'] . "</td>"; echo "<td>" . $row['telephone'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['openinghours'] . "</td>"; echo "</tr>"; } echo "</table>";
}
} else {
echo "0 results";
}

mysqli_close($conn);
?>

最佳答案

@user2983401 指出,您有两个 while 循环。摆脱第一个:

// Create connection
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT id, title, image, description, tekst, address, website, telephone, email, openinghours FROM ExperienceUtrecht";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
// output data of each row
/*while($row = mysqli_fetch_assoc($result)) { Not needed*/
echo "<table border='1'> <tr> <th>ID</th> <th>Title</th> <th>Image</th> <th>Description</th> <th>Tekst</th> <th>Address</th> <th>Website</th> <th>Telephone</th> <th>Email</th> <th>Opening Hours</th> </tr>";
while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['image'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "<td>" . $row['tekst'] . "</td>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['website'] . "</td>"; echo "<td>" . $row['telephone'] . "</td>"; echo "<td>" . $row['email'] . "</td>"; echo "<td>" . $row['openinghours'] . "</td>"; echo "</tr>"; } echo "</table>";
/*} Not needed*/
} else {
echo "0 results";
}

mysqli_close($conn);
?>

关于php - 显示除第 1 行以外的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43548463/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com