一个href加载数据库项onClick

i'm developing a simple Content Management System that allow users to create categories and subcategories. This is the code.

$categories = mysql_query("SELECT * FROM categories");
while($row = mysql_fetch_array($categories)) {
    $text = $row['text'];
    $id = $row['id'];

    echo "<li><a href='?category=$id'>$text</a></li>";

}

Now, all works fine as expected but i would like that when a user click on <li> items the system loads subcategories related to the selected category. In PHP i can't do this so i need to use JavaScript but i don't understand why. I wrote this code.

<script type="text/javascript">

    function loadSubCategories() {
        <?php

        if(isset($_REQUEST['category'])) {
            echo "Hello";
        }           

        ?>  
    }

</script>

and obviously

echo "<li><a href='?category=$id' onClick='javascript:loadSubCategories()'>$text</a></li>";

This not works because nothing appear when i click on a link. How can i solve?

Pass id attribute in function call like this:

 echo "<li><a id="$id" onClick='javascript:loadSubCategories(this.id)'>$text</a></li>";

Then you can use jQuery/Ajax, try something like this:

$( document ).ready(function() {

    function loadSubCategories(id){
        $.ajax({
            url     : Class/Method-Name,
            type    : 'POST',
            data    : form_data,
            success : function(msg){
                // Action
            }
        }),                
    }

});