我正在尝试从PHP中对表进行排序,但我得到一个错误的错误"警告:mysqli_fetch_array()期望参数1为mysqli_result"
<?php
$con = mysqli_connect('localhost' , 'root' , '' ,'profile'); */ connection */
$fname= 'fname';
$age = 'age';
if (isset($_GET['order'])) {
$order = $_GET['order'];
}
else {
$order = 'fname';
}
if (isset($_GET['sort'])) {
$sort = $_GET['sort'];
}else{
$sort = 'ASC' ;
}
$res = "SELECT * FROM profile ORDER BY $order $sort";
$sql = mysqli_query($con,$res); */connecting with mysql database from $con */
?>
<table>
<tr>
<th><a href="?order=fname&&sort=$sort">First Name</a></th>
<th><a href="?order=age&&sort=$sort">Age</a></th>
</tr>
<?php while($rows=mysqli_fetch_array($sql)) : ?>
<tr>
<td><?php echo $rows[$fname];
?></td>
<td><?php echo $rows[$age];
?></td>
</tr> <?php endwhile; ?> </table>