How to get four logins corresponding to the given id? Now the code is:

mysql_query("SELECT login FROM name WHERE id = '$array[0]' OR id = '$array[1]' OR id = '$array[2]' OR id = '$array[3]' LIMIT 4"); 

Closed due to the fact that the essence of the question is not clear to the participants: aleksandr barakin , Alexey Shtanko , DeKaNszn , dlarchikov , Vladyslav Matviienko Jun 16 '15 at 5:53 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    In the SQL part, it is better for you, probably, to request pairs of id - login , otherwise it is not clear to which id which login belongs:

     SELECT id, login FROM name WHERE id IN (?,?,?,?); 

    Instead of question marks you need to substitute your values. mysql_query() uses an obsolete PHP extension, which will soon be excluded from work. Use MySQLi or PDO . With PDO it will look something like this:

     $dbh = new PDO('mysql:dbname=testdb;host=127.0.0.1', 'username', 'password'); $sth = $dbh->prepare('SELECT id, login FROM name WHERE id IN (?,?,?,?)'); $sth->execute( $array); // ваш массив с 4 значениями $logins = $sth->fetchAll(); 

    The result will be an array containing up to 4 lines, if all are found, with associative arrays for each line found. Those. for the first pair you can pick up:

     $login1 = $logins[0]['login']; $id1 = $logins[0]['id'];