我面临着mysql_fetch_assoc功能的问题没有,我需要用PHP mysql_fetch_assoc
功能来获取数据库中的数据,但它是返回任何结果(空白页),下面是我的代码:mysqli_fetch_assoc返回在屏幕上
功能:
function confirm_query($watever){
global $connection;
if (!$watever) {
die("Database query failed! " . mysqli_error($connection));
}
}
function find_admin(){
global $connection;
$query = "select * from admins ";
$query .= "order by username asc";
$admin_set = mysqli_query($connection, $query);
confirm_query($admin_set);
return $admin_set;
}
管理页面:
<?php $connection = mysqli_connect($host, $name, $password, $db); ?>
<?php $admin_set = find_admin(); ?>
<table>
<tr>
<th style="text-align: left; width: 200px;">Username:</th>
<th colspan="2" style="text-align: left;">Action:</th>
</tr>
<?php while($admin = mysqli_fetch_assoc($admin_set)) { ?>
<tr>
<td><?php echo htmlentities($admin["username"]);?></td>
<td><a href="edit_admin.php?id=<?php echo urldecode($admin["id"]); ?>">Edit</a></td>
<td><a href="delete_admin.php?id=<?php echo urldecode($admin["id"]); ?>" onclick="return confirm('Are you sure');">Delete</a></td>
</tr>
<?php }?>
</table>
什么是'confirm_query'? – Sadikhasan
嗨, 谢谢,confirm_query是一个功能检查连接: function confirm_query($ watever){ global $ connection;如果(!$ watever){ die(“Database query failed!”。mysqli_error($ connection)); } } – babydragon86
您确定'admin_set'实际上包含任何数据吗? '的print_r($ admin_set);退出;'在'mysqli_query'行后面 – Alex