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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:35:27+00:00 2026-05-12T05:35:27+00:00

I have 3 Tables: Regions Table which has 1500 Towns in it. Categories Table

  • 0

I have 3 Tables:

  1. Regions Table which has 1500 Towns in it.
  2. Categories Table which has 1800 categories.
  3. Companies Table containing businesses.

What I need to do is grab a town, for example Brimingham and list in an Array which categories have businesses using our main Companies Table, so we don’t have any categories stored in the array which don’t have businesses in Brimingham.

The problem I have is the size of the array being stored, when I populate all the towns with the serialized array I cant even open the table to browse. See below array example:

a:9:{s:8:”Bailiffs”;s:1:”1″;s:20:”Business Consultants”;s:1:”1″;s:25:”Car Garages and Mechanics”;s:1:”1″;s:35:”Farming Livestock and Other Animals”;s:1:”2″;s:19:”Fashion Accessories”;s:1:”1″;s:6:”Hotels”;s:1:”1″;s:20:”Post Office Services”;s:1:”1″;s:13:”Schools State”;s:1:”1″;s:14:”Wood Craftsmen”;s:1:”1″;}

Can anyone suggest an alternative solution?

Cheers

  • 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-12T05:35:27+00:00Added an answer on May 12, 2026 at 5:35 am

    I’d suggest a totally different approach that gets rid of the storage problem entirely, and should make your app more efficient. Storing serialized arrays full of information that can be retrieved from your database anyway is redundant and highly inefficient. The best approach here would be to normalize your data.

    You should create a fourth table, perhaps called ‘region_categories‘, which will be a simple lookup table:

    CREATE TABLE region_categories (
      regionId int unsigned not null,
      categoryId int unsigned not null,
      PRIMARY KEY(regionId,categoryId)
    );
    

    Now, instead of saving everything to an array, for each town/region you should instead populate this table with the categories that are in that town. Your data size is very small, as all you are storing is a pair of ids.

    When it comes time to retrieve the categories for a given region, you just have to run a simple SELECT statement:

    SELECT category.*
    FROM region_categories AS rc LEFT JOIN categories AS c ON rc.categoryId=c.categoryId
    WHERE rc.regionId=[whatever region you're dealing with]
    

    Now you can iterate through your results, and you’ll have all the categories for that region.

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

Sidebar

Related Questions

I have an agency table, which has a many-to-many relationship with zones, countries, regions,
I have a two tables. One has manufacturer information and includes the regions where
I have several sparsely populated tables in an Excel workbook from which I need
I have duplicated rows in tables. I have two table which are connected by
I have tables linked by FK, I query on the first table using entity
In my database I have tables that define types for example Table: Publication Types
I have a rather large table with 150,000 + records. It has a lot
I have a XML file that I need to populate multiple SQL tables, and
I have two tables both of which have columns StartDate and EndDate. I'm trying
I need help in creating a query for my database. I have 2 tables,

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.