My first query got all related ids from Table A
and another query got all necessary ids
from Table B
.
Now I want to make 3rd query by those ids which not match above both query.
Example:
- Query return: 1 , 5, 10, 15.
- Query return: 5.
- Query want to make by: 1, 10, 15.
Here is my work:
//1st query:
foreach((array)$f2_ids as $indx => $value) {
$g = mysqli_query($dbh,"SELECT id FROM update WHERE
`to_id`='".$pg_ids[$indx]."' AND `from_id`='".$f2_ids[$indx]."' GROUP BY id") or die(mysqli_error($dbh));
while ($rows = mysqli_fetch_assoc($g)) {
$ids[] = $rows['id'];
}
}
//2st query:
foreach((array)$ids as $id) {
$p = mysqli_query($dbh,"SELECT post_id FROM view WHERE `post_id`='".$id."' AND `user_id` ='".$session->id."'") or die(mysqli_error($dbh));
while ($rows = mysqli_fetch_assoc($p)) {
$Vids[] = $rows['post_id'];
}
}
//3st query: I tried which not get proper result.
foreach((array)$ids as $index => $value) {
if($ids[$index] !== $Vids[$index]){ // avoid match ids
//echo $ids[$index];
$j = mysqli_query($dbh,"SELECT * FROM update WHERE `id`='".$ids[$index]."' ORDER BY created DESC");
}
}
UPDATE:
foreach((array)$ids as $id) {
$p = mysqli_query($dbh,"SELECT *
FROM update
WHERE `id` = '$id'
AND `id` NOT IN (SELECT post_id
FROM view
WHERE `post_id`='$id'
AND `user_id`='$myid')
ORDER BY created DESC") or die(mysqli_error($dbh));
$rows = mysqli_fetch_assoc($p);
$id = $rows['id'];
echo $id;
}