There is a code. How to change it to get a random output?

<?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> 
  • one
    Random conclusion of what? - avengerweb
  • Sorry, did not explain. Output from table $table = "article"; random phrase phrases: content . I have the code under the number 2 print "<td>$data[2]</td>"; - Greg888

1 answer 1

 SELECT * FROM `$table` ORDER BY RAND() LIMIT $first, $users_on_page 
  • Thank you very much! - Greg888
  • one
    With a rand order - $ first is not needed. Accordingly, the first query is also (which should look like "SELECT ** COUNT ** ( id ) from $table ") - istem
  • If you tell me the solution to the problem I will be more difficult Based on my code How to make the conclusion of the phrases "By rating". I have a rating in the database in another rating_post table, the column up (or on the account $ data [1]) ____ Phrases: Table article______________ {id} __ {timestamp} ___ {content} ___ {author} ______ {19} ______ {2012- 10-20} _______ {Now for the cats ...} ___ {“Author”} ___ Rating: Table rating_post id_post up down _____ 21 2 0 - Greg888