php - How to order comments by likes/dislikes in MySQL -
on website people can thumbs or thumbs downwards comment. utilize 2 tables:
$sql = "create table content ( id int not null auto_increment, primary key(id), content text not null, date date, time time )";
and
$sql2 = "create table ratings ( rating_id int auto_increment primary key not null , rating varchar (10) not null , id int not null , ip varchar (50) not null )";
the info stored in ratings follows:
comment id like/dislike user ip 1 l 86.42.173.83 1 d 86.42.173.43 2 l 86.42.173.79 2 l 86.42.173.34 2 d 86.42.173.22
the problem i'm having i'm finding extremely hard create sql statement order comments amount of likes have.
if has ideas on how appreciated.
it easier if stored likes integers , not letters.
i added likes using case statement , grouped comment.
select c.content, sum(case when r.rating = 'l' 1 else -1 end) overallrating content c left bring together ratings r on r.id = c.id grouping c.content order overallrating
php mysql sql
No comments:
Post a Comment