Try to display the query result to display on the same page
<p>Hi guys I need help again... I am trying to list out the main category list, and besides each category, there is a view button to see its subs and display within the same page. Here is my code:</p>

<pre><code>&lt;table width="100%" align="center" style="margin-top:20px;"&gt;
&lt;tr&gt;&lt;td align="center"&gt;&lt;font size="6"&gt;Categories&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;?php
$sql = mysql_query("Select * FROM categories WHERE top_cat_id = 0")
?&gt;
&lt;div id="mainCat"&gt;
&lt;form method="POST" id="viewSub" action=""&gt;
&lt;table width="100%" align="center" class="categories"&gt;
&lt;tr&gt;&lt;td colspan="3" style="background-color:#000; color:#FFF; font-size:16px;"&gt;Main Categories&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align="center" width="10%" style="font-size:14px; font-weight:bold;"&gt;ID&lt;/td&gt;
&lt;td align="center" style="font-size:14px; font-weight:bold;"&gt;Categorie Name&lt;/td&gt;
&lt;td align="center" width="30%" style="font-size:14px; font-weight:bold;"&gt;Subcategories&lt;/td&gt;&lt;/tr&gt;
&lt;?php
while($data = mysql_fetch_array($sql))
{
    echo '&lt;tr&gt;&lt;input type="hidden" name="cat_id" id="cat_id" value="'.$data['cat_id'].'"&gt;&lt;td align="center"&gt;'.$data['cat_id'].'&lt;/td&gt;';
    echo '&lt;td align="center"&gt;'.ucwords(strtolower($data['cat_name'])).'&lt;/td&gt;';
    echo '&lt;td align="center"&gt;&lt;input type="submit" name="submit" value="View" /&gt;&lt;/td&gt;&lt;/tr&gt;';
}
?&gt;
&lt;/table&gt;&lt;/form&gt;
&lt;/div&gt;
&lt;script type="text/javascript"&gt;
$(function() {
    $("#viewSub").bind('submit',function() {
        var cat_id = $('#cat_id').val();
        $.post('subcategories.php',{cat_id:cat_id}, function(data){
        $("#subCat").html(data);
        });
        return false;
    });
);
&lt;/script&gt;
&lt;div id="subCat"&gt;

&lt;/div&gt;
</code></pre>

<p>As you can see, I guess the jquey function only listen to the first View button, because no matter with button I click, it only returns me the subs of the first main category. Is there any way to make it work? like using onclick action? I am not good with javascript, so I need help to get this to work... Thank you.</p>
