salve, come dal titolo perché questo codice .. mi visualizza sempre tutti i record ad seconda del nome che gli passo ma prende le cose di altre cose invece di visualizzare solo i suoi .?

ecco il codice un po complesso.. ma c'e la sto facendo.

la query è questa:

codice:
$pg->query("SELECT post_categories.title as _title, users.username as _username, post.*, post_tags.*, DATE_FORMAT(post.data_reg,'%d/%m/%Y ore %H:%i') as 'data_it' FROM users 
       INNER JOIN post 
          ON users.id = post.id_users INNER JOIN post_categories 
          ON post_categories.id = post.id_categories 
          INNER JOIN post_tags ON post_tags.id_tags = '".$id_tags."'
        WHERE post_tags.id_tags=".$id_tags." and post.active=1 order by post.data_reg desc", $client_news_id_categories, $pagina, $db);
codice:
<?phpinclude("inc.php"); 
$title = "News";
include(''.$theme.'header.php');
echo "<div id=\"f\">\n";
echo "<div id=\"content\">\n";
?>
<div class="center">
<p class="post_back_button"><a href="news.php">Torna indietro</a></p>
</div>
<?php


    $pagina = (isset($_GET["pagina"])) ? trim ((int)$_GET["pagina"]): '';
    $tags_name =$_GET["tags"];


    $query = "select * from tags where name = :name";
    $stmt = $db->prepare( $query );
    
    $stmt->bindParam(':name', $tags_name, PDO::PARAM_STR);
    
    $stmt->execute();
    $row = $stmt->fetch();
    $num = $stmt->rowCount();
    
    if($num > 0)
    {
    
    
        $title = $row["name"];
        $id_tags = $row["id"];
    
    }else
    {
    }




if(empty($tags_name))
{
    echo '<p class="info_empty_url">Url - Vuoto</p>';
}else
{
    ?><p class="news_categories_info">tags : <?php echo ucfirst($row["name"]); ?></p>
    
    <?php
    echo $id_tags;
    $pg = New paginator($db);
    $pg->query("SELECT post_categories.title as _title, users.username as _username, post.*, post_tags.*, DATE_FORMAT(post.data_reg,'%d/%m/%Y ore %H:%i') as 'data_it' FROM users 
       INNER JOIN post 
          ON users.id = post.id_users INNER JOIN post_categories 
          ON post_categories.id = post.id_categories 
          INNER JOIN post_tags ON post_tags.id_tags = '".$id_tags."'
        WHERE post_tags.id_tags=".$id_tags." and post.active=1 order by post.data_reg desc", $client_news_id_categories, $pagina, $db);
    if($record = $pg->Show())
    {
    ?>
    
    
    <?php
        foreach($record as $row)
        {
         ?>
    <div id="post">
    <fieldset>
    <legend>News : <?php echo $row["title"]; ?></legend>
    <p class="posted">Categoria:&nbsp;[&nbsp;&nbsp;<span class="post_title"><?php echo ucfirst($row["_title"]); ?></span>&nbsp;&nbsp;]&nbsp;&nbsp;Postato <?php echo $row["data_it"]; ?> by <span class="post_username"><?php echo $row["_username"]; ?></span></p>    
    <p><?php echo $id_tags;?></p>
    <div class="content">
    <?php echo htmlspecialchars_decode($row['intro']); ?>
</div>        
<?php if(strlen($row["content"]) > 0)
{
?>
<div class='post_links_more'><p><a href='news_view.php?id=<?php echo $row["id"]; ?>'>Leggi Tutto</a></p></div>
<?php
}
?>
    </fieldset>
    </div>
         <?php
         
        }
    ?>
    
    <?php
    }
    else
    {
        echo '<p class="info_empty_no_data">Vuoto</p>';
    }
    ?>
    <?php
    if($link = $pg->Link(3))
    {
        ?>
        <a href="?id=<?php echo $id_categories; ?>&pagina=<?php echo $link['first']?>">&laquo;</a> <?php
            foreach($link['before'] as $bf)
            {
                ?><a href="?id=<?php echo $id_categories; ?>&pagina=<?php echo $bf?>"><?php echo $bf?></a> <?php
            }
            ?><?php echo $link['current']?> <?php
            foreach($link['after'] as $at)
            {
                ?><a href="?id=<?php echo $id_categories; ?>&pagina=<?php echo $at?>"><?php echo $at?></a> <?php
            }
        ?><a href="?id=<?php echo $id_categories; ?>&pagina=<?php echo $link['last']?>">&raquo;</a>
        <?php
    }
    ?>
    <?php
}
echo "</div>\n";
echo "</div>\n";
?>
<div id="sidebar">
    <?php include("include/sidebar.php"); ?>
</div>
<?php
include(''.$theme.'footer.php');


$db = null; 


?>

vi ringrazio molto e aspetto le vostre risposte.

grazie infinite.