Php 菲律宾';s仅返回1行,然后复制它
我想知道是否有人能向我解释为什么mysql表中有5个不同的行时它只返回1行 它只显示所有5行中的第1行,因为我将它放在一个while循环(HTMLcode)中,这样它就可以打印所有其他行,而不仅仅是第一行Php 菲律宾';s仅返回1行,然后复制它,php,mysql,row,Php,Mysql,Row,我想知道是否有人能向我解释为什么mysql表中有5个不同的行时它只返回1行 它只显示所有5行中的第1行,因为我将它放在一个while循环(HTMLcode)中,这样它就可以打印所有其他行,而不仅仅是第一行 提前感谢:) PHP代码 HTML代码 <?php echo 'hello, ' . $_SESSION['username']; echo ' '; echo $_SESSION['id']; ?>
提前感谢:)
PHP代码
HTML代码
<?php
echo 'hello, ' . $_SESSION['username'];
echo ' ';
echo $_SESSION['id'];
?>
<div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="TableCol1"> Username </th>
<th class="TableCol2"> First Name </th>
<th class="TableCol3"> Last Name </th>
<th class="TableColOpt"> Options </th>
</tr>
</thead>
<tbody>
<?php
while ($check) {
echo '<tr>';
echo '<td class="prEach1">' . $username . '</td> ';
echo '<td class="prEach1">' . $firstname . '</td> ';
echo '<td class="prEach3">' . $lastname . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$UserID.'">View</a> '
. '</td>';
echo '</tr>';
$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
}
?>
</tbody>
</table>
</div>
<?php
echo 'hello, ' . $_SESSION['username'];
echo ' ';
echo $_SESSION['id'];
?>
<div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="TableCol1"> Username </th>
<th class="TableCol2"> First Name </th>
<th class="TableCol3"> Last Name </th>
<th class="TableColOpt"> Options </th>
</tr>
</thead>
<!-- This is the category fields on the list. -->
<tbody>
<?php
//$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
while ($check) {
echo '<tr>';
echo '<td class="prEach1">' . $check['Username'] . '</td> ';
echo '<td class="prEach1">' . $check['FirstName'] . '</td> ';
echo '<td class="prEach3">' . $check['LastName'] . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$check['UserID'].'">View</a> '
. '</td>';
echo '</tr>';
$check = $sqlQuery->fetch(PDO::FETCH_ASSOC); //THIS SHOULD BE AT THE BOTTOM JUST BEFORE THE WHILE LOOP ENDS
}
?>
</tbody>
<!-- This is the get methods of the properties, where the output of the user put in the Property form will be shown -->
</table>
</div>
用户名
名字
姓
选择权
-------------------------------------------------------
编辑
我找到了解决方案
PHP代码
HTML代码
<?php
echo 'hello, ' . $_SESSION['username'];
echo ' ';
echo $_SESSION['id'];
?>
<div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="TableCol1"> Username </th>
<th class="TableCol2"> First Name </th>
<th class="TableCol3"> Last Name </th>
<th class="TableColOpt"> Options </th>
</tr>
</thead>
<tbody>
<?php
while ($check) {
echo '<tr>';
echo '<td class="prEach1">' . $username . '</td> ';
echo '<td class="prEach1">' . $firstname . '</td> ';
echo '<td class="prEach3">' . $lastname . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$UserID.'">View</a> '
. '</td>';
echo '</tr>';
$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
}
?>
</tbody>
</table>
</div>
<?php
echo 'hello, ' . $_SESSION['username'];
echo ' ';
echo $_SESSION['id'];
?>
<div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th class="TableCol1"> Username </th>
<th class="TableCol2"> First Name </th>
<th class="TableCol3"> Last Name </th>
<th class="TableColOpt"> Options </th>
</tr>
</thead>
<!-- This is the category fields on the list. -->
<tbody>
<?php
//$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
while ($check) {
echo '<tr>';
echo '<td class="prEach1">' . $check['Username'] . '</td> ';
echo '<td class="prEach1">' . $check['FirstName'] . '</td> ';
echo '<td class="prEach3">' . $check['LastName'] . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$check['UserID'].'">View</a> '
. '</td>';
echo '</tr>';
$check = $sqlQuery->fetch(PDO::FETCH_ASSOC); //THIS SHOULD BE AT THE BOTTOM JUST BEFORE THE WHILE LOOP ENDS
}
?>
</tbody>
<!-- This is the get methods of the properties, where the output of the user put in the Property form will be shown -->
</table>
</div>
用户名
名字
姓
选择权
我想知道是否有人能向我解释为什么mysql表中有5个不同的行时它只返回1行
查看循环时内部发生的情况
while ($check) {
echo '<tr>';
echo '<td class="prEach1">' . $username . '</td> ';
echo '<td class="prEach1">' . $firstname . '</td> ';
echo '<td class="prEach3">' . $lastname . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$UserID.'">View</a> '
. '</td>';
echo '</tr>';
$check = $sqlQuery->fetch(PDO::FETCH_ASSOC);
}
然后像这样循环遍历结果集
// your code
<?php
while ($row = $sqlQuery->fetch(PDO::FETCH_ASSOC)){
echo '<tr>';
echo '<td class="prEach1">' . $row['Username'] . '</td> ';
echo '<td class="prEach1">' . $row['FirstName'] . '</td> ';
echo '<td class="prEach3">' . $row['LastName'] . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$row['UserID'].'">View</a> '
. '</td>';
echo '</tr>';
}
?>
// your code
//您的代码
//你的代码
这看起来与您的另一个问题几乎完全相同,其中给出了答案,但未标记为已解决。那么,这个有什么不同呢?编辑:你也犯了同样的错误。谷歌的“php pdo fetch”产生了“从结果集中获取下一行”。看看这一切;试着去理解发生了什么。@Fred ii-嗨,是的,我想出了另一个问题,现在我想知道如何显示所有的行,而不仅仅是一行,但这一行只有在有行的时候才显示第一行。那么为什么Barmar的答案旁边没有绿色的勾号,你没有回应他的最后评论呢?编辑:好的,你现在标记了。@Fred ii-对不起,我是新来的,我不知道你应该这么做,我以后会这么做的。谢谢,我也找到了一个解决方案,我刚刚在那里编辑了我的帖子,谢谢你THO:)我们的答案有点相似,但不是你把它作为语句$row=$sqlQuery->fetch(PDO::fetch_ASSOC)
我把我的放在while循环中,就在while循环结束之前:)@MarkyB我正在写答案,因此没有看到您的编辑。很高兴问题解决了。干杯!:)
// your code
<?php
while ($row = $sqlQuery->fetch(PDO::FETCH_ASSOC)){
echo '<tr>';
echo '<td class="prEach1">' . $row['Username'] . '</td> ';
echo '<td class="prEach1">' . $row['FirstName'] . '</td> ';
echo '<td class="prEach3">' . $row['LastName'] . '</td> ';
echo '<td class="prEach4 optlinks"> '
. '<a href="profile.php?UserID='.$row['UserID'].'">View</a> '
. '</td>';
echo '</tr>';
}
?>
// your code