Главная страница  /  Занятия  /  #14  /  MySQL-команды ORDER BY, LIMIT, LIKE и функция COUNT

MySQL-команды ORDER BY, LIMIT, LIKE и функция COUNT

Задание:

Рассказать о MySQL-командах ORDER BY, LIMIT, LIKE и о функции COUNT.

php-документ (index.php):

   <?
    $dbhost = 'localhost';
    $dbname = '******_education';
    $dbuser = '******_education';
    $dbpass = '******';
   
    mysql_connect($dbhost, $dbuser, $dbpass);
    mysql_select_db($dbname);
   
    mysql_query("set names utf-8;");
    mysql_query("set collation_connection=utf8_general_ci;");
   
    $educationResource = mysql_query("select user_name, user_age from education_users;");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].', '.$currentRecord[1].'<br>'; } echo '<br>';
    $educationResource = mysql_query("select user_name, user_age from education_users order by user_age;");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].', '.$currentRecord[1].'<br>'; } echo '<br>';
    $educationResource = mysql_query("select user_name, user_age from education_users order by user_age desc;");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].', '.$currentRecord[1].'<br>'; } echo '<br>';
    $educationResource = mysql_query("select user_name from education_users limit 2;");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].'<br>'; } echo '<br>';
    $educationResource = mysql_query("select user_name from education_users limit 1,2;");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].'<br>'; } echo '<br>';
    $educationResource = mysql_query("select count(*) from education_users;");
$currentRecord = mysql_fetch_row($educationResource); echo 'Количество записей: '.$currentRecord[0].'<br>'; echo '<br>';
    $educationResource = mysql_query("select user_name from education_users where user_name like '%пе%';");
while($currentRecord = mysql_fetch_row($educationResource)) { echo $currentRecord[0].'<br>'; } echo '<br>'; mysql_close(); ?>

Результат:

Результат выполнения задания можно посмотреть здесь.