Display the star First then normal

Hi i am just wondering how could i display the name with a star Frist then the normal names without stars under the bottom

i got it working but it dont sort the 3 i have for now on top only 2

[https://imgur.com/a/vr3N0Y5] (The Preview off the name with stars )

     $sql = " SELECT * FROM links where approved='1' ORDER BY hotlink='1' LIMIT ";    
     $result = mysqli_query($link, $sql);
     while($user = mysqli_fetch_assoc($result)) {

   if ($user['hotlink'] == "1") {           
echo '
<span class="badge badge-pill badge-warning  pull-left"><i class="fa fa-star" aria-hidden="true"></i>'.$user['name'].'</span>

} else {

echo '<h5><md style="color: teal ;cont-weight:1000;background-color:#000000d1;padding: 0px 6px 6px 6px;border-radius: 6px;text-shadow: 1px 1px 1px rgb(23, 135, 224);">'.$user['name'].'</md></strong></h4>';


Well in your SQL you would have ORDER BY hotlink DESC (no = 1 bit). This would order the rows in decending order, putting all the records with hotlink = 1 first in the set. If you want to then say order by name in ascending order, you can also sort by that… ORDER BY hotlink DESC, name ASC.

Now I am assuming that hotlink only has two possible values 1 and 0. If that is the case, then it is just a matter of looping through your set and for each row that has hotlink == 1, you show the star, else don’t show the star (what you show there).

This should give you the desired result of having all those with hotlink = 1 at the top and sorted by name, with the ones without stars below those. Of course make the necessary tweaks if hotlink has other values. They should be minor changes.

I hope this helps. :slight_smile:


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.