要使用mysqli和php在html表上显示多行结果,它只显示第一行,但我没有看到代码中的错误
我只从数据库中获取第一行要使用mysqli和php在html表上显示多行结果,它只显示第一行,但我没有看到代码中的错误,php,mysqli,Php,Mysqli,我只从数据库中获取第一行 <?php require('testconfig.php') ?> <html> <head> </head> <body> <?php $sql="SELECT * FROM item "; $sqlll=mysqli_query($conn,$sql) or die ("cant fetch data"); $resu
<?php require('testconfig.php') ?>
<html>
<head>
</head>
<body>
<?php
$sql="SELECT * FROM item ";
$sqlll=mysqli_query($conn,$sql) or die ("cant fetch data");
$result=mysqli_fetch_assoc($sqlll);
?>
<table border='1'>
<tr>
<td>r.no</td>
<td>name</td>
<td>prices</td>
</tr>
<?php
while ($row=mysqli_fetch_assoc($sqlll))
{
echo "<tr>";
echo "<td>".$result['RNO']."</td>";
echo "<td>".$result['ITEMNAME']."</td>";
echo "<td>".$result['PRICE']."</td>";
echo "</tr>";
echo "<br/>";
}
?>
</table>
</body>
</html>
将while循环变量的名称更改为result,一切都会正常工作。在不循环$result之前,您循环了$row并在循环中使用了$result
<?php require('testconfig.php') ?>
<html>
<head>
</head>
<body>
<?php
$sql="SELECT * FROM item ";
$sqlll=mysqli_query($conn,$sql) or die ("cant fetch data");
?>
<table border='1'>
<tr>
<td>r.no</td>
<td>name</td>
<td>prices</td>
</tr>
<?php
while ($result=mysqli_fetch_assoc($sqlll))
{
echo "<tr>";
echo "<td>".$result['RNO']."</td>";
echo "<td>".$result['ITEMNAME']."</td>";
echo "<td>".$result['PRICE']."</td>";
echo "</tr>";
echo "<br/>";
}
?>
</table>
</body>
</html>
介意把大写字母改成小写或驼色吗?它被视为叫喊。while循环中的$result应改为$row。如果你改变了这一点,一切都会好起来的。事实上,你只看到一个结果,因为你是从$result打印的,而不是循环槽。你逃出twitter了吗?顺便说一句,这是一个打字错误。错误报告会告诉你的。这看起来也像是另一个可能被删除的账户的转载,我记得不久前的那个账户很特别;事实上是一两天。你为什么要把第一排排排在while循环之外呢?哦,天哪,我不敢相信它起作用了。谢谢你帮了我这么多
<?php require('testconfig.php') ?>
<html>
<head>
</head>
<body>
<?php
$sql="SELECT * FROM item ";
$sqlll=mysqli_query($conn,$sql) or die ("cant fetch data");
?>
<table border='1'>
<tr>
<td>r.no</td>
<td>name</td>
<td>prices</td>
</tr>
<?php
while ($result=mysqli_fetch_assoc($sqlll))
{
echo "<tr>";
echo "<td>".$result['RNO']."</td>";
echo "<td>".$result['ITEMNAME']."</td>";
echo "<td>".$result['PRICE']."</td>";
echo "</tr>";
echo "<br/>";
}
?>
</table>
</body>
</html>