Reply to Re: MySQL Query

Your name:

Reply:


Posted by Alvaro G. Vicario on 08/26/06 17:36

*** thesimplerules@gmail.com escribió/wrote (26 Aug 2006 10:07:08 -0700):
> I want to have a field where I store a list of what categories that
> particular row falls under, I don't know which format to do or how I
> would query it.

The logical approach in a normalized database would be to create a separate
table with the following fields:

foo_to_categories
=================

id_foo - Foreign key
id_category - Foreign key

> For example, row1 might belong to categories 1, 3 & 7

Stored data would like like this:

1 1
1 3
1 7

> I'd want to be able to query all rows belonging to 3 and get row1.

SELECT *
FROM categories
INNER JOIN foo_to_categories
ON categories.id_category=foo_to_categories.id_category
WHERE foo_to_categories.id_category=3



Replace "foo" with the actual object name, I figured out it won't be "row"
unless you're building a ticket selling system ;-P


P.S. Code is untested

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация