user3374948 user3374948 - 6 months ago 29
MySQL Question

Getting array specific data from mysql

I'm trying to get data from a mysql database... but I only need results specified by an array... for example I have a database which is populated with member data: username, email etc... and another table where I store per member their contact list like... So I'm looking on a way to display member their contact list... I'm just not clear on whats the best way... any tips are welcome... for example:

$result = mysql_query("select contact_id from member_contact_list");

$contacts = array();

while ($row = mysql_fetch_array($result)){
$c_array[] = $row[ 'username' ];

$c_array = implode( ',', $existing_users );

$sql = "SELECT * FROM members WHERE id="c_array[]"";

Its a little hard to explain... I hope someone gets what I mean.


IN will help you like

$sql = "SELECT * FROM members WHERE id IN (".$c_array.")";

Consider that $c_array is an string that consists member id imploded with ,.