PHP查询不会在html表中显示所有结果 [英] PHP query not showing all results in html table

查看:104
本文介绍了PHP查询不会在html表中显示所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下查询来显示我的数据库中的所有用户:

 < ul class =names> ; 
< table>
< tr>
< th> Navn< / th>
< th>电子邮件< / th>
分数< / th>
< / tr>
<?php
$ connection = mysql_connect('localhost','users','password'); //空白字符串是密码
mysql_select_db('users');

$ query =(SELECT * FROM oneusers); //你不需要一个;就像你在SQL
$ result = mysql_query($ query);

$ row = mysql_fetch_array($ result);

while($ row = mysql_fetch_array($ result)){//创建一个循环来遍历结果
echo< tr>< td> 。 $ row ['iUserName']。 < / TD>< TD> 中。 $ row ['iUserEmail']。 < / TD>< TD> 中。 $ row ['iUserCash']。 DKK< / td>< / tr>; // $ row ['index']这里的索引是一个字段名称
}

mysql_close(); //确保关闭数据库连接
?>
< / table>
< / ul>

但由于某些原因,它并不显示所有数据。

仅显示具有iUserId 2而不是一个的用户。

有人对可能出现什么问题有所了解吗?

我可以使用iUserId 1的凭据登录,并且它在登录页面显示的信息很好。



但不在这里:S

解决方案删除行 $ row = mysql_fetch_array($ result);



因为此行开始从查询结果中提取记录。首先获取的记录是id 1 的记录,你什么也不做。



然后你开始 echo 其他记录,但已经跳过id 1 的记录。


So I have the following query to show all users from my database:

<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>

But for some reason it doesnt show all the data.

In only shows the user with iUserId 2 and not one.

Does anyone have an idea of what might be wrong?

I can log in with iUserId 1's credentials, and it shows fine the info on the login page.

But not here :S

解决方案

Remove line $row = mysql_fetch_array($result);

Because this line starts to fetching records from your query results. First fetched record is record with id 1 and you do nothing with it.

Then you start echoing other records, but record with id 1 is already skipped.

这篇关于PHP查询不会在html表中显示所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆