There is an array. It is required to select from the database all the rows where the value of the specified column will be equal to one of the array elements.

The essence of the question is how to do it correctly , shortly and quickly. Everybody knows how to make an invention, but a competent approach is required.

example:

$arr = array(0=>1, 1=>2, 2=>4 /* ... n=>m */) $sql=mysql_query("SELECT title,value FROM $someTable WHERE id='любому из элемента масива $arr'"); while ($data=mysql_fetch_assoc($sql)) //do something 

    1 answer 1

    Usually they do this (I will sign in separate lines so that it would be clearer):

     $sql = mysql_query( "SELECT title, value FROM $someTable WHERE id IN (" . join(',', $array) . ")" ); 

    It works max_allowed_packet as long as the length of the request in max_allowed_packet doesn’t max_allowed_packet .

    And yes - it is almost correct, short and fast :) To be completely correct, the elements of the array (depending on the type) should be quota / escaped. In php it does, it seems, the function mysql_escape_string()

    • Thank - Getans