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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:04:01+00:00 2026-05-23T10:04:01+00:00

I have created this database schema and with help from several users on here,

  • 0

I have created this database schema and with help from several users on here, I have a database which takes user submitted business entries stored in the business table, which are additionally grouped under one or several of about 10 catagories from the catagories table, in the tbl_works_catagories table by matching the bus_id to the catagory id.

For example, bus_id 21 could be associated with catagory_id 1, 2, 5, 7, 8.

CREATE TABLE `business` (
`bus_id` INT NOT NULL AUTO_INCREMENT, 
`bus_name` VARCHAR(50) NOT NULL, 
`bus_dscpn` TEXT NOT NULL, 
`bus_url` VARCHAR(255) NOT NULL,
PRIMARY KEY (`bus_id`)
)

CREATE TABLE `categories` (
`category_id` INT NOT NULL AUTO_INCREMENT, 
`category_name` VARCHAR(20) NOT NULL, 
PRIMARY KEY (`category_id`)
)

CREATE TABLE `tbl_works_categories` (
`bus_id` INT NOT NULL, 
`category_id` INT NOT NULL
)

Now, what i want to do next is a search function which will return businesses based on the catagory. For example, say one of the businesses entered into the business table is a bakers and when it was entered, it was catagorised under Food (catagory_id 1) and take-away (catagory_id 2).

So a visitor searches for businesses listed under the Food catagory, and is returned our friendly neighbourhood baker.

As with all PHP/MySQL, i just can’t (initially anyway) get my head around the logic, never mind the code!

  • 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-05-23T10:04:02+00:00Added an answer on May 23, 2026 at 10:04 am

    You should setup foreign keys in your tables to link them together.

    CREATE TABLE `business` (
    `bus_id` INT NOT NULL AUTO_INCREMENT, 
    `bus_name` VARCHAR(50) NOT NULL, 
    `bus_dscpn` TEXT NOT NULL, 
    `bus_url` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`bus_id`)
    )
    
    CREATE TABLE `categories` (
    `category_id` INT NOT NULL AUTO_INCREMENT, 
    `category_name` VARCHAR(20) NOT NULL, 
    PRIMARY KEY (`category_id`)
    )
    
    CREATE TABLE `tbl_works_categories` (
    `bus_id` INT NOT NULL, 
    `category_id` INT NOT NULL,
    FOREIGN KEY (`bus_id`) REFERENCES business(`bus_id`),
    FOREIGN KEY (`category_id`) REFERENCES categories(`category_id`)
    )
    

    Then your search query would be something like:

    SELECT b.*
    FROM business b, categories c, tbl_works_categories t
    WHERE 
       b.bus_id = t.bus_id AND
       c.category_id = t.category_id AND
       c.category_id = *SOME SEARCH VALUE*
    

    which using JOIN would be written as:

    SELECT b.*
    FROM business b
      JOIN tbl_works_categories t
        ON b.bus_id = t.bus_id
      JOIN categories c
        ON c.category_id = t.category_id
    WHERE c.category_id = *SOME SEARCH VALUE*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a table on an Oracle 10g database with this structure :
I have a database schema like this picture: I want to write a query
I need to create a Firebird Database programmatically using DBExpress. I have done this
I have created this code, and when I run it, don't get any errors
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I have created something like this and this . In effect I have a
I have dialog created like this $('#add_error').click(function(e) { $('<div>') .load('/someaction/format/html/') .dialog({ title: 'Some title',
I have created a MultiSelectList like this: MultiSelectList UsergroupID = new MultiSelectList(_ug.GetUsergroups(), UsergroupID, UsergroupName,
i have created a module with this among others this function in it: <?php
I have created a static library following this link . But I am facing

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.