我正在尝试从phpmyadmin获取第一行。在尝试以不同的方式进行操作后,我想问一下。现在,问题在于它正在不断刷新浏览器。
我尝试添加一个死,但是我在mysqli / php方面不是很好
$sql2="SELECT * FROM stellingen WHERE REGIOID=1;";
$records2 = mysqli_query($con, $sql2);
$row = mysqli_fetch_assoc($records2);
while ($stellingen = mysqli_data_seek($records2, 0)){
echo "<p>".$stellingen['Stelling']."</p>";
}
我希望php能够获取第一个数据。在循环的情况下,下一个数据将不需要在页面的后面。
更多代码
<div class="stellingen">
<div class="stelling-wrapper" id="btn1">
<img src="images/button.svg" alt="Show more..." class="btn" id="bton">
<p type="button" class="stelling">
<?php
$sql2="SELECT * FROM stellingen WHERE REGIOID=1;";
$records2 = mysqli_query($con, $sql2);
$row = mysqli_fetch_assoc($records2);
while ($stellingen = mysqli_data_seek($records2, 0)){
echo "<p>".$stellingen['Stelling']."</p>";
}
/*
if ($recordscheck2 > 0){
while ($stellingen = mysqli_fetch_assoc($records2)){
echo "<p>".$stellingen['Stelling']."</p>";
}
}*/
?>
</div>
<div id="p1">
<table id="tabel" border=1px class="data">
<tr>
<th>Title</th>
<th>Source</th>
<th>Weight</th>
<th>Date</th>
</tr>
<?php
$sql1="SELECT * FROM stelling WHERE stelling_iD=1;";
$records1 = mysqli_query($con, $sql1);
$recordscheck = mysqli_num_rows($records1);
if ($recordscheck > 0){
while ($stelling = mysqli_fetch_assoc($records1)){
echo "<tr>";
echo "<td>".$stelling['Title']."</td>";
echo "<td>".$stelling['Source']."</td>";
echo "<td>".$stelling['Wheight']."</td>";
echo "<td>".$stelling['Timer']."</td>";
echo "</tr>";
}
}
?>
</table>
</div>
答案 0 :(得分:1)
Okey,所以您在mysqli_data_seek()
循环中使用while()
,这是错误的...
<?php
if($result = mysqli_query($con, "SELECT * FROM stellingen WHERE REGIOID=1;")) {
mysqli_data_seek($result, 0);
$row = mysqli_fetch_assoc($result);
echo "<p>{$row["Stelling"]}</p>";
}
?>
应该为您工作。
[编辑]我更正了变量名。