Newbie needs help with Basic Sorting - How do I group items using say an id tag?

This is a discussion on "Newbie needs help with Basic Sorting - How do I group items using say an id tag?" within the PHP Forum section. This forum, and the thread "Newbie needs help with Basic Sorting - How do I group items using say an id tag? are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jul 31st, 2006, 02:10
New Member
Join Date: Apr 2006
Location: Australia
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Newbie needs help with Basic Sorting - How do I group items using say an id tag?

Greetings - I am a absolute newbie to PHP/MySQL and would appreciate kickstart help.

I have attempted a tutorial presented at DMX Zone but failed to make it work. You may care to see what I mean by looking at their site. I will add the link details once this posting has been accepted by your forum.

Here is my scenario
Basic Setup:

Database: MySQL
id Name
0 Fruit
1 Banana
1 Pineapple
1 Kiwi Fruit
1 Apples
0 Vegetable
6 Tomatoes
6 Peas
6 Carrots


Output required:
Fruit
Apples
Banana
Kiwi Fruit
Pineapple
Vegetable
Carrots
Peas
Tomatoes

Requirement:
Depending on the designated id, all items starting with 0 should display as bold category headings listed in alphbetical order and all associated products matching that category would be listed - also in alphabetical order.

Ultimately I will be changing the id column to a specific Products Part No. but the above example is consistant with the DMX Zones example and is simple (hopefully) to illustrate how I may achieve the desired output.

A working code sample - or suggested tutorial sites would be greatfully received

Thanks in anticipation


PS. I'm using Dreamweaver 8 / PHP / MySQL (latest versions)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 31st, 2006, 02:17
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie needs help with Basic Sorting - How do I group items using say an id tag?

GROUP BY
in the database command.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jul 31st, 2006, 11:30
New Member
Join Date: Apr 2006
Location: Australia
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie needs help with Basic Sorting - How do I group items using say an id tag?

Thanks - can you give me a sample script for same? Please.

Check out the tutorial I started with at DMXZone at (all one line address):

http://www.dmxzone.com/showDetail.asp?
d=2&NewsId=4937

I'm a newbie and have followed the tutorial but DW8 seems to generate different code to that displayed. I presume there is an error here somewhere but I don't know enough to work in out myself.

A little personal coaching / mentorship would be greately received.

Thanks heaps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jul 31st, 2006, 14:26
Most Reputable Member
Join Date: Aug 2005
Location: North Wales, United Kingdom
Age: 21
Posts: 1,093
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie needs help with Basic Sorting - How do I group items using say an id tag?

Dont use dreamweaver, it doesnt handle dynamic code well. Thats where your going wrong, hand code it in an editor such as crimson editor.

To download it go to www.downloads.com then put crimson editor in the search box.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jul 31st, 2006, 16:11
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie needs help with Basic Sorting - How do I group items using say an id tag?

Really your database is not optimally formed. Here is my immediate reaction for db MYSQL:

Code: Select all
 Table items
ID  Item
1    Carrot
2    Apple
3    Orange
4    Banana
5    Broccoli
6    Squash

 Table groups
1    Fruit
2    Vegetable

 Table key_id
group_id  2         item_id  1
             1                     2
             1                     3
             1                     4
             2                     5
             2                     6

MySQL Query: Select * from items, groups WHERE key_id.group_id=groups.id AND key_id.item_id=item.id GROUP BY key_id.group_id DESC
I think that's right. I always use table names because I'll use the same column names, that is, I'll have group_id to designate the id of a group entry and group_id in the key table. Here I just used "id" but there's still an identically named column in two tables.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 2nd, 2006, 14:47
Junior Member
Join Date: Jan 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Newbie needs help with Basic Sorting - How do I group items using say an id tag?

Mason, the group by clause is wrong in the code you have posted. You need to include EVERY non aggregate column from the select clause in the group by clause. Failing to do so in any other database except mysql will result in an error and the code won't produce a result. Mysql warns in their manual about GROUP BY HIDDEN FIELDS and that it can produce incorrect results.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
newbie, needs, help, basic, sorting, group, items, using, say, tag

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help sorting an array djeyewater PHP Forum 6 Apr 18th, 2008 15:16
Newbie Question- Basic HTML email method="post" Bagel Web Page Design 4 Aug 18th, 2006 12:03
Basic Sorts - How do you group items using id tag? Newbie Kickstart AceTutor PHP Forum 7 Aug 15th, 2006 12:42


All times are GMT. The time now is 15:33.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42