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 8620099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:30:05+00:00 2026-06-12T06:30:05+00:00

I have a UL list in one div, built using php that retrieves data

  • 0

I have a UL list in one div, built using php that retrieves data from mysql. Here is the code:

<div class="sidebar_section">
<h1>Browse Categories</h1>
<?php
include('config.php');
//Connect to mysql server
...
//Select database
...
$categories_sql = "SELECT * FROM tbl_catagory";
$categories_query = mysql_query($categories_sql) or die (mysql_error());
$rsCategories = mysql_fetch_assoc($categories_query);
?>
<form>
<ul>
<?php do { 
?>
<li><a href = "#" id="cat_<?php echo $rsCategories['ID']; ?>"><?php echo $rsCategories['CatagoryName']; ?></a></li>
<?php
} while ($rsCategories = mysql_fetch_assoc($categories_query));
?>
</ul>
</form>
</div>

How do I get the user’s selection into another .php file so that I can display only the products associated with this category? Of course, in the other file I’d do SELECT * FROM table WHERE categoryname=whatever the user selected.

  • 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-12T06:30:07+00:00Added an answer on June 12, 2026 at 6:30 am

    The answer to this varies a lot.

    First I will try to answer with the easiest approach I can think of:

    Make the href of the anchor something like this:

    <li><a href="category.php?catId=<?php echo $rsCategories['ID']; ?>" 
           id="cat_<?php echo $rsCategories['ID']; ?>">
        <?php echo $rsCategories['CatagoryName']; ?></a></li>
    

    Then just create a category.php script in which you use the id from the $_GET array.

    <?php
    $categoryId = mysql_real_escape_string($_GET['catId']);
    $products_sql = "SELECT * FROM ebook WHERE category = '$categoryId'";
    //proceed with the rest
    ?>
    

    Since you’re going with links in a list and you are using # as href, I will consider that you might desire on using AJAX. Here is one way of doing all this.

    First: let’s give those lists a class, which we will call “category-choose” (awful naming, sorry, just change it as you wish). This will allow that a single jQuery .click or .live(‘click’, …) will be enough, instead of having to add one event per id.

    <li><a href="#<?php echo $rsCategories['ID']; ?>" 
           class="category-choose">
        <?php echo $rsCategories['CatagoryName']; ?></a></li>
    

    Second: just to make it easy on us, let’s use the href as “#” (where is just a number indicating the id). Now we can do the following jQuery code:

    $(document).ready(function() {
        $('.category-choose').live('click', function () {
            var catId = this.href.substr(1);
            $("#content_right").load('content_displaycatproducts.php?catId=' + catId);
        });
    });
    

    Now, in the PHP script you do the same done in the previous method.

    Hopefully I didn’t screw up somewhere since I have no way to test this code 🙂 Any errors or malfunctioning you get, please report and I will fix ASAP.

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

Sidebar

Related Questions

I have a list of div's. This is one div structure: <div class=commentWrap id=@Model.CommentId>
i have one list in php page with follwoing script <div id='demo' style=padding-left:20px> <select
I have one list that I want to take a slice of, reverse that
I have one spinner, and I am populating that. I have list of values
I have a list of e-mails from one database which I want to check
I am trying to build a Stack List using DIV's I have 3 divs
I have only one list div and I want to make it scrollable. I
I have a list where each li element contains two div inside one div
I have built two control containers on a page, one is using jquery-ui tabs
I have one list that contains Student informations lsStudents = context.GetTable<Student>().Where(p => p.M_Id.Equals(1)).ToList(); And

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.