andrew has asked for the wisdom of the Perl Monks concerning the following question:

I have a category from the shopping cart I'm making called "Chirstmas" it's I.D is 16, this chirstmas, has subcategories, that have items in it. I wanna pull the two newest items from Christmas.

Screen Shot of categorie:
http://www.merchandisemarket.net/a.gif

Screen Shot of items:
http://www.merchandisemarket.net/b.gif

This means I have to find Christmas Subcategories, loop through them, find the the two newest items (by latest I.D). Myabe you would get all the images in christmas in a list then find the two (but what if I wanted more than two like 6, "$lim = 6;").

Replies are listed 'Best First'.
Re: Looping Database
by talexb (Chancellor) on Oct 16, 2002 at 18:49 UTC

    Sounds like you want to do some SQL:

    select * from items where subcategory = "Christmas" order by id desc l +imit 2

    Not really a Perl question, but whatever.

    --t. alex
    but my friends call me T.

    psI highly recommend HyperSnapDX. Buy a license!

Re: Looping Database
by dug (Chaplain) on Oct 16, 2002 at 18:55 UTC
    Assuming that the field "category" in the table "items" corresponds to the field "id" in the table "category" and you want to solve this using SQL instead of Perl and you are using Mysql (may work on other databases as well, but untested) ...

    which is a lot of assumtions :^)

    You could use
    SELECT items.* FROM items, category WHERE items.category = category.id + ORDER BY items.id DESC LIMIT 2;

    If you are going to be doing a bit of database driven programming, it's certainly worth your time to spend a bit of time studying SQL. I'm just beginning to realize its power for certain tasks.

    -- dug
Re: Looping Database
by rdfield (Priest) on Oct 17, 2002 at 08:08 UTC
    Before plunging into the depths of SQL and other assorted technical stuff, you might want invest in some spell checking software - nothing puts off customers more than badly laid out adverts.

    As for the technical aspects to your question, I'm afraid you'll have to give Perl a rest for a while and concentrate on database design and query languages.

    rdfield