Here is the script:

<?php $host='localhost'; // имя хоста (уточняется у провайдера) $database='db'; // имя базы данных, которую вы должны создать $user='user'; // заданное вами имя пользователя, либо определенное провайдером $pswd=''; // заданный вами пароль $dbh = mysql_connect($host, $user, $pswd) or die("Не могу соединиться с MySQL."); mysql_select_db($database) or die("Не могу подключиться к базе."); mysql_query("SET NAMES 'utf8'"); $query = "SELECT opisanie FROM `db` where tema='тема'"; $res = mysql_query($query); $row = mysql_fetch_row($res); echo $row[0]; ?> 

Suppose we have found several results for the key "topic", in which variable is the first and second results? PS $ row [1] tried, did not help.

Strange. If you write $query = "SELECT * FROM db where tema='тема' limit 0,2"; , then the output is normal (but the information that I need is not displayed), if you write $query = "SELECT opisanie FROM db where tema='тема' limit 0,2"; , then an error occurs: Notice: Undefined offset: 1 in ...

    3 answers 3

     $res = mysql_query("SELECT `opisanie` FROM `db` where tema='тема';") or die(mysql_error()); echo '<pre>'; while ($row = mysql_fetch_object($res)) print_r($row); echo '</pre>'; 

    Get used to the normal code.

    PS: Access to the object field: $row->opisanie

    PPS: you request one field, therefore only $row[0] . Select all fields - query " SELECT * FROM ... "

      You need to sort through the cycle:

       while($row = mysql_fetch_row($res)){ echo $row[0]; } 

      And to get two lines, we write the following request:

       $query = "SELECT opisanie FROM `db` where tema='тема' limit 0,2"; 
      • And how to get all the lines where the key is found? - nick777 2:24
      • And there the error is: Notice: Undefined offset: 1 in ... - nick777
       $query = "SELECT * FROM `db` where tema='тема'"; while($row = mysql_fetch_row($res)){ echo $row[0]." - ".$row[1]; } 

      Try to make a complete sample and look at the fields, maybe you made a mistake where?

      • Strange. If you write <code> $ query = "SELECT * FROM db where tema = 'topic' limit 0,2"; </ code>, then the output is normal (but not the information that I need), if you write < code> $ query = "SELECT opisanie FROM db where tema = 'topic' limit 0,2"; </ code>, then an error occurs: Notice: Undefined offset: 1 in ... - nick777
      • try to write like this $ query = "SELECT opisanie FROM db where tema = 'subject is' limit 0,2"; Muscular quotes stand up, this is one of the solutions, sometimes it helps. - Artem
      • Understood, such single skewed quotes. Framed It did not help ... - nick777
      • I calculated the number of occurrences of the word I am looking for, made a simultaneous conclusion of this number and information from the opisanie table. Writes 2 entries, it is strange that anyway the error is displayed ... - nick777