There is a code. How to change it to get the conclusion of the phrases "by rating"?

<?php //имя сервера $serverMySql = "localhost"; // логин $db_log = "*******"; // пароль $db_pass = "*****"; function db_connect($serverMySql, $db_log, $db_pass) //create connection { $r = mysql_connect($serverMySql, $db_log, $db_pass); return $r; } //база данных $database = "perecc"; //название таблицы в базе $table = "article"; //кол-во пользователей на странице $users_on_page = "100"; //подключаемся db_connect($serverMySql, $db_log, $db_pass); mysql_select_db($database); mysql_set_charset('utf8'); // страницы if (empty($_GET["p"])) { $_GET["p"] = "1"; } $p = $_GET["p"]; // защита от ввода if (preg_match("/[%a-z_@.,^=:;Р°-СЏ\"*()&$#в„–+\-!?<>\~`|[{}\]]/i", $p)) { die(header("Location:sluch_list.php")); } // формируем запрос $count = mysql_num_rows(mysql_query("SELECT `id` from `$table`")); // считаем страницы $total = ceil($count / $users_on_page); if ($p > $total) { $p = $total; } // формируем запрос $first = $p * $users_on_page - $users_on_page; $result = mysql_query("SELECT * FROM `$table` LIMIT $first, $users_on_page"); ?> <?php while ($data = mysql_fetch_array($result)) // цикл вывода { print "<tr>"; print "<td>&nbsp;</td>"; print "<td>&nbsp;</td>"; print "<td>&nbsp;</td>"; print "</tr>"; print "<tr>"; print "<td>$data[0]</td>"; print "<td>$data[2]</td>"; print "<td>$data[1]</td>"; print "</tr>"; } ?> </table> 

The rating I have in the database is in another rating_post table, the column up (or on the account $ data [1])

Phrases: table article

 {id} _ _{timestamp} {content} {author} {21}___{2012-10-20}_ {Сейчас котам...} {«Автор»} Рейтинг: Таблица rating_post {id_post} {up} {down} {21} _ _ {2}__{0} 
  • 2
    Instead of this nonsense: if (empty ($ _ GET ["p"])) {$ _GET ["p"] = "1"; } $ p = $ _GET ["p"]; if (preg_match ("/ [% a-z _ @., ^ = :; Р ° -СЏ \" * () & $ # in „- + \ - !? <> \ ~` | [{} \]] / i ", $ p)) {die (header (" Location: sluch_list.php "));} you need to use this: $ p = intval (isset ($ _ GET ['p'])? $ _ GET ['p ']: 1); - Photon

1 answer 1

 SELECT * FROM `$table` AS tb LEFT JOIN rating_post AS rp ON (tb.id = rp.id_post) ORDER BY rp.up LIMIT $first, $users_on_page" 

There is nothing to check, but can it be so?