Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:41:46+00:00 2026-06-17T05:41:46+00:00

I need help again… I am trying to list out the main category list,

  • 0

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:

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

</div>

As you can see, I guess the jQuery 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:41:47+00:00Added an answer on June 17, 2026 at 5:41 am

    Here is a working code:

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

    I am assuming your AJAX request works fine.

    P.S. Use prepared statements for your SQL query further. Because this code is not secure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your help again :) I'm trying to do a plugin with jQuery
I need help again with some regular expressions I'm trying to do (still under
Need a little help again. Say I have an unordered list, and I want
looks like I need help again! :-/ Im trying to read this XML file
I need your help again. So I have a simple list <ul> <li>First</li> <ul
I am in a difficult situation and need help again There is this aspx
I again need help by you, this time I struggle with covariance, contravariance, delegates
Sorry to bother again, but I really need help transforming this Python2 code into
Once again I need your Help, am thanking you as every time you helped
I need your help with this one again. I want to send special characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.