RE: TR: Manipulating "categories" in a php database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok great stuff, thank you, that has enlightened me on the method I need to
develop :)

Oh and about the double msg, sorry fighting with outlook here, not my usual
client ;)

Regards,

Tim

-----Message d'origine-----
De : Robert Cummings [mailto:robert@xxxxxxxxxxxxx] 
Envoyé : mardi 30 janvier 2007 19:40
À : Tim
Cc : php-general@xxxxxxxxxxxxx
Objet : Re:  TR: Manipulating "categories" in a php database

On Tue, 2007-01-30 at 19:29 +0100, Tim wrote:
> Hello all,
>
> This is more of a conceptional question rather then a technical one.
> 
> I am developping an online catalog, the catalog is a standard
> categorie/subcat/subsubcat system using the following logic in my
database:
>
> cat_id   cat_name
>
> 10        DVD
> 1010     DVD/Action
> 1020     DVD/Adventure
> 20        CD
> 2010     CD/Reggae
> 2020     CD/Electro
>
> Up to now I enter the category id's manually from an administration
console.
> 
> I would like to be able to have my console automagically generate a cat_id
> when my users add categories (so they don't have to bother with that
aspect
> of adding a category)

Either make the cat_id auto increment and let MySQL generate it for you,
or lock the table, get the last ID, create the new row with ID = LastID
= 1, and then unlock the table.

>  and I would also like to be able to move a category up
> or down in the way it displays on the page, as of now I am sorting by
cat_id

Order the data in a linked list. Move the link in question up and down
as necessary.

> I have been for a while trying to develop a logical scheme to be able to
> generate the id's and change their cat_id to reflect a "new" position in
how
> it displays (displaying DVD/Action after DVD/Adventure for example I would
> need to change the cat_id from 1010 to something above 1020 say 1021).
This
> is fine as I can test the previous elements cat_id and add or subtract 1
but
> I get stuck when I have a cat_id say 1010 that I would want to put between
> 1011 and 1012. I'm having trouble developing the algorithm that would
allow
> this.. 

Use a new field called display_order or display_rank. When moving items
around via linked list regenerate the display_order based on the
position within the list. Save these values to the database. When
selecting categories from the database order based on this field, and
then any other field you want (in case of no ordering). For instance I
usually order by display_order, title. And only set ordering information
for specific fields I want positioned at the front or end of the list.
This is slightly more complicated though since you need to preserve no
ordering for naturally ordered items and when moving order items around
they should be able to skip past or before all naturally ordered items.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux