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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:38:36+00:00 2026-06-15T00:38:36+00:00

i have two table: category id | name products id | cat_id | name..

  • 0

i have two table:

category
id | name

products
id | cat_id | name..

Like the title, I want to create a menu of category, when I click on one category, it will display all products in that category.I have try several way but it won’t works! This is my menu.php

    try { 

    $dbh = new PDO("mysql:host=$hostname;dbname=...", $username, $password);


    $sql = "select * from category";
    echo "<table>";
    echo "<tr><th>ID</th><th>Name</th></tr>";
    foreach ($dbh->query($sql) as $row)
        {
        $c_id=$row['c_id'];
        echo "<tr>";
        echo "<td>" . $row['c_id'] ."</td>";
        echo "<td><a href='deal_list.php?cat_id=$c_id'>" . $row['c_name'] . "</td>";



        echo "</tr>";
        }
    echo "</table>";

        $dbh = null;
    }
    catch(PDOException $e) { echo $e->getMessage(); }

?>

and this is my product list

try { 
    $cat_id = $_GET['cat_id'];
    $dbh = new PDO("mysql:host=$hostname;dbname=..", $username, $password);

    $sql = "select id,name,description,price,groupbuy_price, CEIL((groupbuy_price/price)*100) AS saving,current_buyer,maximum_buyer,expired_time,status,sum_img,cat_id,c_name from groupbuy,category where c_id=cat_id";
    echo "<table border=2px>";
    echo "<tr><th>Name</th><th>Description</th><th>Price</th><th>Group buy price</th><th>Saving</th><th>Number of current buyer</th><th>Maximum Buyer</th><th>Expired Time</th><th>Status</th><th>Category</th><th>Sumary image</th></tr>";
    foreach ($dbh->query($sql) as $row)
        {
        $id=$row['id'];
        echo "<tr>";
        echo "<td>" . $row['name'] . "</td>";
        echo "<td>" . $row['description'] ."</td>";
        echo "<td>" . $row['price'] . "</td>";
        echo "<td>" . $row['groupbuy_price'] ."</td>";
        echo "<td>" . $row['saving'] .'%' ."</td>";
        echo "<td>" . $row['current_buyer'] ."</td>";
        echo "<td>" . $row['maximum_buyer'] ."</td>";   
        echo "<td>" . $row['expired_time'] ."</td>";
        echo "<td>" . $row['status'] ."</td>";
        echo "<td>" . $row['c_name'] . "</td>";



?>
        <td><img src="<?php echo $row['sum_img']?>" width="50px" /></td>
<?php
        echo "<td><a href='delete_deal.php?id=$id'>Delete</a></td>"; 
        echo "<td><a href='deal_detail.php?id=$id'>Detail</a></td>"; 
        echo "<td><a href='edit_deal.php?id=$id'>Edit</a></td>"; 


        echo "</tr>";
        }

    echo "</table>";

        $dbh = null;
    }
    catch(PDOException $e) { echo $e->getMessage(); }

?>
  • 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-15T00:38:38+00:00Added an answer on June 15, 2026 at 12:38 am

    looks like you just need to replace

    $sql = "select id,name,description,price,groupbuy_price, CEIL((groupbuy_price/price)*100) AS saving,current_buyer,maximum_buyer,expired_time,status,sum_img,cat_id,c_name from groupbuy,category where c_id=cat_id";
    

    with

    $sql = "select id,name,description,price,groupbuy_price, CEIL((groupbuy_price/price)*100) AS saving,current_buyer,maximum_buyer,expired_time,status,sum_img,cat_id,c_name from groupbuy,category where c_id={$cat_id}";
    

    but for secure reasons change also in begining

    $cat_id = (int) $_GET['cat_id'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that look like this: Products: id category name description active
I have two fields... one is category name and other is document title... When
I have two tables, one called product_text with a products name, description and category.
I have two tables, categories and products. I am using CodeIgniter. Categories CREATE TABLE
I have two tables 1: itemInfo product_id brand name category 1 Garden Goodcake cake
My prob in brief: I have two tables namely category and product. table: category
I have two table views, when user clicks one cell of the first, second
I have two table cells, with dynamic content. Table cell one works fine, when
I have two table. One table hold key column and xml column. Other table
I have two tables namely 'categories' & 'products' as follows: categories id | name

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.