当我从我的数据库(MySQL)中选择一些数据时,它会显示除第一行之外的所有行。如何解决?
代码
Apr 21, 2017 7:21:03 AM org.apache.solr.common.SolrException log
SEVERE: org.apache.solr.common.SolrException: ERROR: [doc=livepublish:/site/components/roadmap/social-responsibility.xml] multiple values encountered for non multiValued field items.item.expiration_dt: [2015-11-19T05:00:00.000Z, 2015-11-24T05:00:00.000Z]
答案 0 :(得分:2)
你有两个while循环。第一个循环已将光标移动到第一个记录。第二个while循环再次移动光标。 建议:将表格标签和表头直接移动到If中并删除第一个循环。
答案 1 :(得分:2)
@ 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);
?>
答案 2 :(得分:0)
//它会起作用。你的逻辑很好但不幸的是你做的只是一个简单的错误。你使用两个while循环来获取相同的记录。
//首先循环获取第一条记录并在内循环运行后,第二条记录和继续记录提取,并尝试打印此记录。