SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: categories

  1. #1
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    categories

    Hi, I have a list of people in several categories, and I want to show them on my list like this:

    categorie 1
    name 1
    name 2
    name 3
    categorie 2
    name 4
    name 5
    name 6
    categorie 3
    name 7
    ...

    Ok, I could have a "SELECT"-String for every categorie, but in my case I have about 50 categories. So what can I do here?
    My tables in the DB are looking like this here
    firstname | lastname | categorie

    Thanx for your help, Alex

  2. #2
    SitePoint Zealot alexk's Avatar
    Join Date
    Nov 2000
    Location
    Sydney, Australia
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can order by category:
    PHP Code:
    SELECT from your_table ORDER BY category
    i'd also recommend you to put the categories info into a separate table:

    user - user_id, firstname, lastname, category_id
    category - category_id, title, etc..

  3. #3
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's not my point, I know how to get the output like that:
    name 1| categorie 3;
    name 2| categorie 1;
    name 3| categorie 6;
    ...
    But I will order my output like this here:

    categorie 1
    name 2;
    ...
    categorie 2
    name 8;
    name 39;
    ...
    categorie 3
    name ...
    ...

    Do you understand what I want? It's just a question how to make the output of the information, not how to get it.

  4. #4
    SitePoint Zealot alexk's Avatar
    Join Date
    Nov 2000
    Location
    Sydney, Australia
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that's exactly how i understood you... ok, here's some more code:
    PHP Code:
    $qres mysql_query("SELECT * from your_table ORDER BY category");
    $old_cat "";
    while(
    $fres=mysql_fetch_array($qres))
    {
        
    $firstname $fres["firstname"];
        
    $lastname $fres["lastname"];
        
    $cat $fres["category"];

        if(
    $cat != $old_cat// if category is changed
        
    {
            
    // print out the category now
            
    echo "$cat<br>";
            
    $old_cat $cat;
        }

        
    // print out the name
        
    echo "$lastname$firstname <br>";

    something like that

  5. #5
    SitePoint Addict
    Join Date
    Feb 2001
    Location
    Shanghai, China
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thank you, that is was I was looking for, it's working fine.
    Sorry for our little misunderstanding.
    Alex

  6. #6
    SitePoint Zealot alexk's Avatar
    Join Date
    Nov 2000
    Location
    Sydney, Australia
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by smorb
    Hey thank you, that is was I was looking for, it's working fine.
    Sorry for our little misunderstanding.
    Alex
    bitte schön


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •