473,654 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

organizing the tables...

hi! i'm trying to builid web catalog and i'm having problems with organizing
my tables. here's what i want:

i have main categories, sub_categories and articles like this:

CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)

and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories
like:
relations
id category subcategory
1 1 1
2 1 2
3 2 3
4 2 4
5 2 5
(...)

how i read results:
1) choose category : script outputs category name
2) sql query gets all sub_categories for selected category from table
"relations"
loop
3) output sub_category name
4) select all articles and prices for selected sub_category from
table "Articles"
5) output atricles and prices
till there's no sub_categories left

(sorry for long post)

my question is:
- is there any more elegant and faster way to do this?

thank you all!
Jul 17 '05 #1
7 1715
Personally I'd store a Category ID In the Sub-cat table,
AND a sub-cat id in teh article table. You could probably speed things up by
storing a CatID in the article table too. But it may be overkill. REally
depends on how much pressure the DB server is under. Make sure to set the all
up as indexes.

db

An noise sounding like ToMeK said:
hi! i'm trying to builid web catalog and i'm having problems with organizing
my tables. here's what i want:

i have main categories, sub_categories and articles like this:

CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)

and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories
like:
relations
id category subcategory
1 1 1
2 1 2
3 2 3
4 2 4
5 2 5
(...)

how i read results:
1) choose category : script outputs category name
2) sql query gets all sub_categories for selected category from table
"relations"
loop
3) output sub_category name
4) select all articles and prices for selected sub_category from
table "Articles"
5) output atricles and prices
till there's no sub_categories left

(sorry for long post)

my question is:
- is there any more elegant and faster way to do this?

thank you all!

--

/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.

Jul 17 '05 #2
thanks for reply, first to say i'm very new to databases and php, so i'm
having slight problems following your reply.
what do you mean by:
"Make sure to set the all up as indexes"

tm

"David Gillen" <Be****@RedBric k.DCU.IE> wrote in message
news:sl******** ***********@car bon.redbrick.dc u.ie...
Personally I'd store a Category ID In the Sub-cat table,
AND a sub-cat id in teh article table. You could probably speed things up by storing a CatID in the article table too. But it may be overkill. REally
depends on how much pressure the DB server is under. Make sure to set the all up as indexes.

db

An noise sounding like ToMeK said:
hi! i'm trying to builid web catalog and i'm having problems with organizing my tables. here's what i want:

i have main categories, sub_categories and articles like this:

CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)

and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories
like:
relations
id category subcategory
1 1 1
2 1 2
3 2 3
4 2 4
5 2 5
(...)

how i read results:
1) choose category : script outputs category name
2) sql query gets all sub_categories for selected category from table
"relations"
loop
3) output sub_category name
4) select all articles and prices for selected sub_category from
table "Articles"
5) output atricles and prices
till there's no sub_categories left

(sorry for long post)

my question is:
- is there any more elegant and faster way to do this?

thank you all!

--

/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.

Jul 17 '05 #3
An noise sounding like ToMeK said:
thanks for reply, first to say i'm very new to databases and php, so i'm
having slight problems following your reply.
what do you mean by:
"Make sure to set the all up as indexes"
You've a primary key in your tables, That is an index.
SELECT * FROM BLAH WHERE <PRIMARY_KEY> = 'whatever'
Queries against the primary key will go very quickly, because it is an index.
Similar, if you know you're going to be running lots of queries against
another field which isn't your primary key when doing the create table call
you add in index (<field_name>) near the end. Check the sql reference for you
database and it'll tell you exactly the syntax to use. It'll just speed things
up. Of course, if you set up every field as an index it won't really improve
things. As there is some extra overhead with inserts and updates.

Hope that helps.

D.
"David Gillen" <Be****@RedBric k.DCU.IE> wrote in message
news:sl******** ***********@car bon.redbrick.dc u.ie...
Personally I'd store a Category ID In the Sub-cat table,
AND a sub-cat id in teh article table. You could probably speed things up

by
storing a CatID in the article table too. But it may be overkill. REally
depends on how much pressure the DB server is under. Make sure to set the

all
up as indexes.

db

An noise sounding like ToMeK said:
> hi! i'm trying to builid web catalog and i'm having problems with organizing > my tables. here's what i want:
>
> i have main categories, sub_categories and articles like this:
>
> CATEGORY_1
> SUB_CAT_1
> Article11
> Article12
> (...)
> SUB_CAT_2
> Article24
> Article25
> (...)
> (...)
> CATEGORY_2
> SUB_CAT_3
> Article35
> (...)
> (...)
> (...)
>
> and this is my idea how to do this:
> 1) first there's table CATEGORIES with "id" and "cat_name"
> 2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
> 3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
> "art_price"
> 4) finally there's table with relations between categories and
> sub_categories
> like:
> relations
> id category subcategory
> 1 1 1
> 2 1 2
> 3 2 3
> 4 2 4
> 5 2 5
> (...)
>
> how i read results:
> 1) choose category : script outputs category name
> 2) sql query gets all sub_categories for selected category from table
> "relations"
> loop
> 3) output sub_category name
> 4) select all articles and prices for selected sub_category from
> table "Articles"
> 5) output atricles and prices
> till there's no sub_categories left
>
> (sorry for long post)
>
> my question is:
> - is there any more elegant and faster way to do this?
>
> thank you all!
>
>

--

/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.


--

/(bb|[^b]{2})/
Trees with square roots don't have very natural logs.

Jul 17 '05 #4
NC
ToMeK wrote:

i'm trying to builid web catalog and i'm having problems
with organizing my tables. here's what i want:

i have main categories, sub_categories and articles like this:

CATEGORY_1
SUB_CAT_1
Article11
Article12
(...)
SUB_CAT_2
Article24
Article25
(...)
(...)
CATEGORY_2
SUB_CAT_3
Article35
(...)
(...)
(...)

and this is my idea how to do this:
1) first there's table CATEGORIES with "id" and "cat_name"
2) then there's table SUB_CATEGORIES with "id" and "subcat_nam e"
3) then table ARTICLES with "id", "subcat_id" , "article_na me" and
"art_price"
4) finally there's table with relations between categories and
sub_categories


Number 4, I think, is completely unnecessary. Instead, consider
adding a `cat_id` field to the `SUB_CATEGORIES ` table.

Also, be sure the following fields are indexed:

CATEGORIES.id
SUB_CATEGORIES. id
SUB_CATEGORIES. cat_id (if you choose to have it, that is)
ARTICLES.id
ARTICLES.subcat _id

Cheers,
NC

Jul 17 '05 #5
Hi,
maybe this helps. You're trying to embed what are really arbitrary
indexes into the structure of your tables containing your data. Why
can't you have a flat table of articles with IDs, and then build
category indexes independently on other tables, whatever structure
they may take in the future.

Articles on futility of modeling:

http://www.bkent.net/Doc/limrec.htm
http://www.bkent.net/Doc/brinmod.htm

Try to avoid foreign keys in the tables containing the basic data
(entities).

HTH

Jul 17 '05 #6
I noticed that Message-ID:
<11************ **********@f14g 2000cwb.googleg roups.com> from
gu******@yahoo. com contained the following:
You're trying to embed what are really arbitrary
indexes into the structure of your tables containing your data. Why
can't you have a flat table of articles with IDs, and then build
category indexes independently on other tables, whatever structure
they may take in the future.
<snip>
Try to avoid foreign keys in the tables containing the basic data
(entities).


Absolutely. An entity relationship diagram would help. To determine
the required number of tables the OP needs to know the relationship
between the entities. For instance one sub category can contain many
articles but can one article appear in many sub categories? If the
answer is yes, the OP has a many to many relationship and a link table
is required.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #7
I assumed that an article can appear in many categories. But I'd go as
far as creating a link table for every relation, even if one-to-one.
I really don't like foreign keys in data tables. ER diagrams are nice
in the abstract, but might lead to more complexity, or make you think
you have an inheritance hierarchy or network or small world or
whatever, when you really only want two layers of tables. The upper
layer is a straight line of tables representing relations, groups,
structures, categories, indexes, inheritance, what have you, the
bottom layer is a straight line of data tables without foreign keys.

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1863
by: GBartgo | last post by:
Hi everybody, I don't know how to initialize the weight vector of each node in the tree. The input is a set of N data in M dimensions. I have to realize a software based on the article "S-TREE: self organizing trees for data clustering and online vector quantization", Marcos M.Campos, Gail A.Carpenter,2000. Thanks
3
4327
by: Jamie | last post by:
Hi, Thanks for the excellent answer to my last question! One more: Does anyone have a method they follow for organizing stylesheets themselves? They seem like they can get bloated and hard to read. Aside from putting all the "h1" rules together, I haven't thought of any way to do it, if it's necessary at all. J.
1
2016
by: Andrea | last post by:
Hi All, I am looking for SOM running under WIN32 and Microsoft Visual Studio 6.0. Can anybody help me? Andrea p.s. I apologize for cross-posting, but I have to solve this problem quickly :|
10
3242
by: Rada Chirkova | last post by:
Hi, at NC State University, my students and I are working on a project called "self-organizing databases," please see description below. I would like to use an open-source database system for implementation and would really appreciate your opinion on whether PostgreSQL is suitable for the project. In general, I am very impressed by the quality of PostgreSQL code and documentation, as well as by the support of the developer community. ...
0
1235
by: netsurfer802 | last post by:
I have a question regarding working with seperate files and organizing these files. The company I'm working for is a small comuter company that calls people that have went to computer trade shows...we have computer based CBTs sent out and learning over the Internet. I'm new in this company and am trying to set up a program that seperates leads that are having not a good response or that we aren't able to contect by phone...and then put...
3
1594
by: Tarscher | last post by:
Hi all, I 'm building a website that provide services for soccer teams. When a user (team) signs up I want to give him some personal space like http://www.soccerteamonline.com/teamname where www.soccerteamonline.com is my registered domain and teamname is the name chosen by the user. I want to have one singel code base meaning that I don't want to copy my code to every new account. Can someone please give me some advice on how to...
1
2551
by: Ushach | last post by:
hi, I want to know about Self Organizing maps.T ounderstand the concept ,I need a small example which explains how clustering is done through self organizing maps?If any body implemented it plz send it to me. Thanks in advance, regards, ...
2
3977
by: jehugaleahsa | last post by:
Hello: I have a bunch of related items that are either parents, children or not directly related to each other. In my case, I have a bunch of database tables joined with foreign keys. Another example would be a family tree. I would like to take a flat list of these items and build the hierarchy. So, in other words, I would like to take one element and figure out its relationship to the other items. When I am all done, I
1
1467
by: Desitech | last post by:
I am getting ready to build a new Database for a Golf Tournament I have each year. I am having trouble organizing how I want to build my tables. I have many golfers that golf each year but usually are part of different teams. Some years they golf some they don't. I want to do history reporting. Like What years did they particiate. What championships did they win. Are there any templates for building tables and how to organize the information....
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.