PHP查询未在html表中显示所有结果
因此,我使用以下查询来显示数据库中的所有用户:PHP查询未在html表中显示所有结果,php,html,mysql,Php,Html,Mysql,因此,我使用以下查询来显示数据库中的所有用户: <ul class="names"> <table> <tr> <th>Navn</th> <th>Email</th>
<ul class="names">
<table>
<tr>
<th>Navn</th>
<th>Email</th>
<th>Score</th>
</tr>
<?php
$connection = mysql_connect('localhost', 'users', 'password'); //The Blank string is the password
mysql_select_db('users');
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$row=mysql_fetch_array($result);
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<tr><td>" . $row['iUserName'] . "</td><td>" . $row['iUserEmail'] . "</td><td>" . $row['iUserCash'] . " DKK</td></tr>"; //$row['index'] the index here is a field name
}
mysql_close(); //Make sure to close out the database connection
?>
</table>
</ul>
纳文
电子邮件
分数
删除行
$row=mysql\u fetch\u数组($result)代码>
因为此行开始从查询结果中获取记录。第一个获取的记录是id为1
的记录,您对它不做任何操作
然后您开始echo
ing其他记录,但id为1
的记录已被跳过。在定义while循环之前获取第一行;一旦进入while循环,它将获取下一行,即第二行。删除第一个mysql\u fetch\u数组($result)
操作
顺便说一句,PHP中原始的mysql
api已被弃用,建议改用mysqli
。我认为您应该这样说
<?php
$connection = mysql_connect('localhost', 'users', 'password'); //The Blank string is the password
mysql_select_db('users');
let all the connection be outside the "ul" tag.
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$query = ("SELECT * FROM oneusers"); //You don't need a ; like you do in SQL
$result = mysql_query($query);
$row=mysql_fetch_array($result);
?>
<ul class="names">
<table>
<tr>
<th>Navn</th>
<th>Email</th>
<th>Score</th>
</tr>
<?php
while($row){ //Creates a loop to loop through results
echo "<tr><td>" . $row['iUserName'] . "</td><td>" . $row['iUserEmail'] . "</td><td>" . $row['iUserCash'] . " DKK</td></tr>"; //$row['index'] the index here is a field name
}
mysql_close(); //Make sure to close out the database connection
?>
</table>
</ul>
Ahh。。我懂了!非常感谢DIt的$CURRENT\u YEAR,停止使用mysql\u
函数。它们很快就会被删除。你认为($row)
会怎么做?提示:$row
的值在哪里更改?$row=mysql\u fetch\u array($result);这将创建数组,然后($row)循环通过。我是说把你的连接代码放在之外或页面顶部,或者可以放在一个单独的文件中,并包括它是的。具体来说,它将第一个结果加载到
$row
中。但是您永远不会更改循环中$row
的值,因此while($row)
while如果有任何数据要显示,则会无限循环。