ORDER BY VIEWS NOT ORDERING RIGHT!

Hello
I have made code but it doesn’t work right
i want it show me top4 popular videos from videos table
Videos: v1 - 5 views , v2 - 7 views , v3 - 10 views , v4 - 8 views
i want it order it by views like

TOP4
V3 - 10 views
V4 - 8 views
v2 - 7 views
v1 - 5 views

my code
[php]
$popular = mysqli_query($conn, “SELECT id,title,season,episode,views,link,img,date FROM videos ORDER BY views DESC LIMIT 4”);
while($row = mysqli_fetch_assoc($popular)) {
[/php]
i dont know why but sometimes it works when i go to video watch it it get more views and order is not right , it is not ordering right i mean it starts to order like

TOP4
v1 - 5 views
V4 - 8 views
v2 - 7 views
V3 - 10 views

or something…

views was text not int sorry

Cast the view field to an int and run it again.

Why is a numeric field of type text anyway?

Are you storing the word “views” in the column as well as a number like you have shown?

nope i views was only numbers and word views i added after

Sponsor our Newsletter | Privacy Policy | Terms of Service