Newbie here. I am having some trouble with PHP some code. I currently have 1 database, consisting of two tables. The two tables are labeled as members
and member_stats
. The members table consists of 3 columns (Fname, Lname, MemberID)
, the member_stats
table consists of 11 columns (user_name, first_name, last_name, avatar, num_friends, num_checkins, total_cards, total_selfmade_cards, total_followings, total_photos)
.
I am fetching the data from my database with
$result = mysqli_query($con,"SELECT * FROM member_stats ");
I am then displaying the data into html table on the page with the following code.
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><div class='user_nav_btn open' ><img src='" . $row[avatar] . "' alt='' /></div></td>";
echo "<td>" . $row['first_name'] . "</td>";
echo "<td>" . $row['MemberID'] . "</td>";
echo "<td>" . $row['num_friends'] . "</td>";
echo "<td>" . $row['total_cards'] . "</td>";
echo "<td>" . $row['num_checkins'] . "</td>";
echo "<td>" . $row['total_selfmade_cards'] . "</td>";
echo "<td>" . $row['total_followings'] . "</td>";
echo "<td>" . $row['total_photos'] . "</td>";
echo "</tr>";
}
I am trying to get the table to print all the rows of data based on the value of total_cards
in order from highest to lowest. No matter what I have tried, I haven’t been able to get it to work. I have only been met with errors on everything I have tried. Any suggestions? I have looked over http://php.net/manual/en/array.sorting.php several times with no luck.