Today I'm having a bit of trouble figuring out a few things in PHP. As I normally do have the tendency to ramble a bit, I will try to keep my question short but concise. Here's what I'm trying to do.
Array #1 is a multidimensional array containing the results from MySQL query done against a user table in the database. It would look as such:
Array ( [0] => Array ( [id] => 79 [firstname] => John [lastname] => Doe [province] => Province [email] => [email protected] [primaryphone] => 123-456-7890 ) [1] => Array ( [id] => 113 [firstname] => Jane [lastname] => Doe [province] => Province [email] => [email protected] [primaryphone] => 123-456-7890 ) )
Array #2 is another multidimensional array containing the results from a MySQL query done against a membership table in the database that contains the id of the user that is associated with the current group. It looks as follows:
Array ( [0] => Array ( [userid] => 79 ) [1] => Array ( [userid] => 115 ) [2] => Array ( [userid] => 124 ) )
What I am trying to do, is for every user returned in array #1, look for a value in array #2 under [userid] that matches the value [id] in array #1. If a match is found for each user, append the key and value [ismember] => 1 for that user in array #1 - if there is not a match, then append the pair [ismember] => 0 to array #1.
I feel that this should be a very simple process, and I'm probably just missing something that is elementary... But I've been going at it for a while now and haven't made much progress. Thank you all for your time and help.
== EDIT == The first array is generated by the following MySQL Query:
$query = "
SELECT
id,
firstname,
lastname,
province,
email,
primaryphone
FROM userstable
";
try
{
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$allusersdetails = $stmt->fetchAll();
The second array is generated by the query:
$query = "
SELECT
userid
FROM membershipstable
WHERE templateid = :currenttemplateid
";
try
{
$stmt = $db->prepare($query);
$stmt->bindParam(':currenttemplateid', $currenttemplateid);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
$templateusers = $stmt->fetchAll();
idand any group that they are associated with. Right now I am using one query to pull the user's info from the first array, and a second query to return their association with the current group.