There is a list of publications, books ... Each such book has 2 values, view = views and like = like .
An example of my code displays entries not as it is correct, I don’t know exactly how you made such output schemes, could you suggest how to properly make such top records at all?


This is actually the request for output from the database:

$sql_top_view = mysql_query(" SELECT COUNT(id) FROM `book` WHERE `view`>='$book[view]' AND `like`>='$book[like]' ORDER BY `view` , `like` LIMIT 1000"); $top_view = mysql_fetch_row($sql_top_view); $top = $top_view[0]; if($top >= 1000){ $top_number_view = '1000+'; }else{ $top_number_view = $top; } echo $top_number_view; 

This code outputs data like this:

 1 место: 7 like , 289 view. 1 место: 9 like , 268 view. 1 место: 17 like , 233 view. 4 место: 7 like , 78 view. и.т.д. 

But you must:

 1 место: 7 like , 289 view. 2 место: 9 like , 268 view. 3 место: 17 like , 233 view. 4 место: 7 like , 78 view. и.т.д. 

But I was also interested in how you can make the like more important than the view, for example, 1 like = 20 view, and if you get a book with a value of 1 like and another with 10 like, then put the first book in the first place?

  • Your request is very strange. There is a count () but no group by. for good in this situation, he must return only one record. And sorting by fields view and like after grouping (which count () introduced to us) does not make sense at all because for a group the value of individual columns is random. maybe there should be sum () or something like that - Mike
  • And if 1 like = 20 view, then apparently the overall rating is calculated as 20*like+view - Mike
  • @Mike Yes, it outputs 1 record, I just showed what scheme it outputs, such as the fact that it adds several records to 1 place and then sharply by 4. - Albert Ushakov
  • @Mike Something I can not. Not yet encountered such a conclusion. Could you show how to do this by example? - Albert Ushakov
  • one
    Write in the question the structure of the tables, preferably with sample data. There is a small explanation to it from which table what to take and what is considered the "most top-rated" - Mike

0