我正在开发members.php页面,虽然我是SQL的新手,但我想知道如何查询并显示从我的用户表中注册的所有用户
到目前为止我的成员页面,我猜它会与第12行和第13行类似?
<?php
ob_start();
session_start();
require_once 'dbconnect.php';
// if session is not set this will redirect to login page
if( !isset($_SESSION['user']) ) {
header("Location: index.php");
exit;
}
// select loggedin users detail
$res=mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href=""></a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact Me</a></li>
<li><a href="#">Members</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Welcome<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="Details.php"><span class="glyphicon glyphicon-user"></span> Account Details</span></a></li>
<li><a href="Details.php"><span class="glyphicon glyphicon-envelope"></span> Messages</span></a></li>
<li><a href="logout.php?logout"><span class="glyphicon glyphicon-log-out"></span> Sign Out</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div id="wrapper">
<div class="container">
<div class="page-header">
<h3>Welcome!</h3>
</div>
<div class="row">
<div class="col-lg-12">
<p>WILL GO HERE!</p>
</div>
</div>
</div>
</div>
<script src="assets/jquery-1.11.3-jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</body>
</html>
<?php ob_end_flush(); ?>
答案 0 :(得分:0)
构造一个SELECT
查询(类似于您在代码中已有的查询),没有任何WHERE
子句,获取结果集并循环遍历以获取行,如下所示:
<div class="row">
<div class="col-lg-12">
<?php
$result_set = mysql_query("SELECT * FROM users");
while($row=mysql_fetch_array($result_set)){
// your code
}
?>
</div>
</div>
旁注:不要使用mysql_*
函数,从PHP 5.5开始不推荐使用它们,并且在PHP 7.0中完全删除它们。请改用mysqli
或pdo
。 And this is why you shouldn't use mysql_*
functions。