Nathan Witten Nathan Witten - 4 years ago 153
SQL Question

How to use explode to grab users

So i am making an inbox and down the side i want all the users this one user has messaged

So this part of the code is in the config.php script

$userassoc = "SELECT * FROM users WHERE `id` = '".$_SESSION['id']."'";
$usercon = $conn->query($userassoc);
$user = mysqli_fetch_array($usercon, MYSQLI_ASSOC);

Then i use this in inbox.php

//find users
$users = explode(',', $user['mid']);

$user['mid'] = (2,3,4)

And 2,3,4 are all users for example 2 = user1 3 = user2 3 = user3

I want it to split them up and then grab information from each user in the $user['mid'] and i know i have to use Explode but i'm not sure where to go after iv used it

Answer Source
$query = "SELECT * FROM users WHERE `id` IN ({$user['mid']})";

try can pass an array value behind the {}.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download