<?php
include("header.php");
include("connect.php");
?>
<?php
$sql = mysqli_query("SELECT * FROM members ORDER BY id ASC");
$id = 'id';
$username = 'username';
$useremail = 'useremail';
$rows = mysqli_fetch_assoc($sql);
echo 'Name: ' . $rows[$id] . '<br />' . 'Username: ' . $rows[$useremail];
?>
我甚至尝试了这一点,但仍然没有......
<?php
include 'includes/connect.php';
$query = "SELECT * FROM members";
$result = mysqli_query ($query);
while($person = mysqli_fetch_array($result)) {
echo "<h1>" . $person['useremail'] . "</h1>";
}
?>
答案 0 :(得分:1)
请检查您是否在connect.php
中正确编写了所有连接变量。您正在使用$rows[$id]
这不是问题,因为您已定义变量$id='id'
。但问题是你没有使用循环。如果你打印
$rows = mysqli_fetch_assoc($sql);
echo $rows[$id];
它只会给出一条记录; 请尝试以下
<?php
$host='localhost';
$user='root';
$pass='';
$db='mydata';//change above four variable as per your setting or write down in connect.php
$con=mysqli_connect($host,$user,$pass) or die(mysqli_error());
mysqli_select_db($con,$db);
$id = 'id';
$username = 'username';
$useremail = 'useremail';
$q="SELECT * FROM members ORDER BY id ASC";
$r=mysqli_query($con,$q);
while($rows=mysqli_fetch_assoc($r)){
echo "Name :".$rows[$username]."<br />"."useremail :".$useremail."<br />";
}
?>