遍历数据库并显示在表中 [英] loop through database and show in table

查看:88
本文介绍了遍历数据库并显示在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历我的用户数据库,以在表中的自己行中显示每个用户名.我只能让它显示一个用户,但要循环遍历其中的行数.代码在下面

I am trying to loop though my users database to show each username in the table in their own row. I can only get it to show one user but loops through this the number of rows there are. Code is below

<?php
require_once ('../login/connection.php');
include ('functions.php');

$query = "SELECT * FROM users";
$results=mysql_query($query);
$row_count=mysql_num_rows($results);
$row_users = mysql_fetch_array($results);

echo "<table>";
    for ($i=0; $i<$row_count; $i++)
    {
    echo "<table><tr><td>".($row_users['email'])."</td></tr>";
    }
    echo "</table>";
?>

谢谢

推荐答案

mysql_fetch_array 获取一行-通常在while循环中使用它可以吃掉结果集中的所有行,例如

mysql_fetch_array fetches a single row - you typically use it in a while loop to eat all the rows in the result set, e.g.

echo "<table>";

while ($row_users = mysql_fetch_array($results)) {
    //output a row here
    echo "<tr><td>".($row_users['email'])."</td></tr>";
}

echo "</table>";

这篇关于遍历数据库并显示在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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