Hi I would like to put a list of ids in an array and loop to select data from a table using "IN" in the where clause. I am not having any success getting this to work. Any suggestions? Note:I am using Mysql database, apache, linux/Windows <? //array with list of friends to display $friend = array('1','2','3','4'); $query = "SELECT first, last, number FROM friend WHERE id IN '$friend'"; $result = mysqli_query($mysqli, $query); PHP:
<? //array with list of friends to display $friend = array('1','2','3','4'); $arrayl = count($friend); $i = 0; while($i < $arrayl) { $query = "SELECT first, last, number FROM friend WHERE `id` = '$friend[$i]'"; $result = mysqli_query($mysqli, $query); $i++; } ?> PHP: Try that, is that what your looking for?
$friend = array('1','2','3','4'); $query = "SELECT first, last, number FROM friend WHERE id IN (".implode(',',$friend).")"; $result = mysqli_query($mysqli, $query); PHP: