Answer the question
In order to leave comments, you need to log in
Query output comparing 2 tables. If a file from one table matches the id of a file from the second table, then display everything else except for it?
There are 2 tables:
admin_files:
id | signature
1 | 1
2 | 1
3 | 1
id | support_id | admin_file_id
1 | 2 | 1
2 | 2 | 2
3 | 2 | 3
function signature($id){
global $connection;
$query = "SELECT COUNT(*) as kol FROM admin_files WHERE signature = 1 ";
$res = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($res);
$kol = $row["kol"];
$query = "SELECT a.* FROM admin_files a JOIN support_files s ON s.admin_file_id = a.id WHERE a.signature= 1 AND s.support_id='$id'";
$res = mysqli_query($connection, $query);
if(mysqli_num_rows($res) == $kol){
return;
}else{
$query = "SELECT a.* FROM admin_files a JOIN support_files s ON s.admin_file_id != a.id WHERE a.signature= 1 AND s.support_id='$id'";
$res = mysqli_query($connection, $query);
if(mysqli_num_rows($res) > 0){
$signature = array();
while($row = mysqli_fetch_assoc($res)){
$signature[$row['id']] = $row;
}
return $signature;
}else{
$query = "SELECT * FROM admin_files WHERE signature = 1 ORDER BY id DESC ";
$res = mysqli_query($connection, $query);
$signature = array();
while($row = mysqli_fetch_assoc($res)){
$signature[$row['id']] = $row;
}
return $signature;
}
}
}
Answer the question
In order to leave comments, you need to log in
From Vladislav's hint, here's what happened, it works as intended.
function signature($id){
global $connection;
$query = "SELECT a.* FROM admin_files a LEFT JOIN support_files s ON s.admin_file_id = a.id AND s.support_id='$id' WHERE s.admin_file_id IS NULL AND a.signature= 1";
$res = mysqli_query($connection, $query);
$signature = array();
while($row = mysqli_fetch_assoc($res)){
$signature[$row['id']] = $row;
}
return $signature;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question