First we request a list of tag identifiers for the file, then it is necessary to get the names of the tags themselves using these identifiers, then print the names on the page. Unfortunately, besides PHP, I didn’t understand other necessary languages, but it seems to me that this can be done with one request, tell me what to operate on?
$fileLabels = []; // запрашиваем перечень меток для текущего файла $query = " SELECT label_id FROM filelabels WHERE file_id = " . $_GET['id']; if ($result = $mysqli->query($query)) { while ($filelabels = $result->fetch_row()[0]) { $labelIDs[] = $filelabels; } // запрашиваем данные о метках (имена меток) для файла $query = " SELECT id, name FROM labels WHERE id IN (" . implode(", ", $labelIDs) . ") "; if ($result = $mysqli->query($query)) { while ($labels = $result->fetch_row()) { $fileLabels[$labels[0]] = $labels[1]; } } else echo $mysqli->error; } else echo $mysqli->error;
inner join(i.e. on ru.so) - you need it. Roughly, it goes like this:SELECT labels.id, labels.name FROM labels INNER JOIN filelabels ON filelabels.label_id = labels.id WHERE filelabels.file_id = YOUR_FILE_ID- BOPOH