PHP While Loops from Arrays

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2010-03-21T15:58:00Z Indexed on 2010/03/21 16:01 UTC
Read the original article Hit count: 252

Filed under:
|
|
|
|

I have a table that contains members names and a field with multiple ID numbers. I want to create a query that returns results where any values in the ID fields overlap with any values in the array.

For example: lastname: Smith firstname: John id: 101, 103

I have Array #1 with the values 101, 102, 103

I want the query to output all members who have the values 101 or 102 or 103 listed in their id field with multiple ids listed.

Array (  [0] => 101
         [1] => 102 
         [2] => 103 )

$sql="SELECT firstname, lastname, id
      FROM members WHERE id LIKE '%".$array_num_1."%'";
$result=mysql_query($sql);

while ($rows=mysql_fetch_array($result)) {
       echo $rows['lastname'].', '.$rows['firstname'].'-'.$rows['id'];
      }

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql