I have a PHP array of data (facebook user ids) which I want to compare against the ones stored in my database (which will consist of thousands). Of those found in the database, I want them to be separated into a new array. I have no idea how to go about this.
So I begin with this array
$ids = 3312312,1232424,1242234,2342636,457456,345345
and end with two
$found = 34234234,234234234
$notfound = 23234234,234234,23423423
If anyone could help, that would be great. I've started this a few different ways but not got very far. Ideally I'd like this comparison to be done in once but I'm not sure if that's possible.
Thanks!
EDIT
From what you've said, I've come up with the following code quickly. It seems to be what you are getting it, but I've not been able to slowly build up to this point so I'm not sure if it's right.
<?php
$con=mysqli_connect("localhost","root","","sabotage");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//json array is being posted to this file from another page
$jsonarray = '[{"name":"Lizzie OBrien","id":"218101335"},{"name":"Ellis Ward","id":"512376340"}]';
$friendlist = json_decode($jsonarray, true);
$found = [];
$notfound = [];
foreach($friendlist as $friend){
$friendid = $friend['id'];
$checkUserID = mysql_query("SELECT facebookid from users WHERE facebookid = '$friendid'");
if (!$checkUserID) {
die('Query failed to execute for some reason');
}
if (mysql_num_rows($checkUserId) > 0) {
$found[] = $id;
}else{
$notfound[] = $id;
}
}
mysqli_close($con);
?>
Which gives me:
Query failed to execute for some reason
Does it make a difference that my facebookid column is an Integer?
Thanks