The page displays the goods in the following way:

<?php $i = 0; $num_rec_per_page=20; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $start_from = ($page-1) * $num_rec_per_page; $sql = "SELECT * FROM goods ORDER BY (clicks/views)*points DESC LIMIT $start_from, $num_rec_per_page"; $rs_result = mysql_query ($sql); ?> <?php while ($row = mysql_fetch_assoc($rs_result)) { //выводятся товары } ?> 

That is, they are sorted using this mathematical operation:

 (clicks/views)*points 

When accessing the page, the GET parameter goods_id can be specified, where the goods IDs are separated by commas (? Goods_id = 1,2,3). It is necessary when sorting goods to raise these goods to the top, that is, they must be first in the list. In the extreme case, it is possible for goods_id to contain only one ID, and the product with that ID is the first to be sorted.

    2 answers 2

    There are two approaches: override the sort or perform two queries. The second one (although you will probably find it wrong) is the most preferable one: first, select the ones you need, then add the others to them (not forgetting to filter those that have already been chosen). These will be two fairly simple queries that will not burden the system too much.
    The approach to redefining sorting is to first sort by matching one of the IDs of interest, and secondly, by show / click rating. To do this, there is a FIELD() construct:

     SELECT * FROM tablename WHERE ... ORDER BY FIELD (id, 1, 2, 3), (остальные сортировки) 

      If you need to output the same id at the top of the request, try adding an ORDER BY clause to the section:

       ORDER BY FIELD(goods_id, 1, 2, 3) DESC 

      Can also be combined with other sorts.