Results 1 to 5 of 5

Thread: PHP listing entries under a certain category

  1. #1
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410

    PHP listing entries under a certain category

    Hi,

    Not a particularly good title, but I was wondering if anyone could help me out doing this please...

    Basically I have a categories database which is printed out in drop-down menu on a form. The user selects the category they want the entry to go into. Each category has an ID, so when they click submit the ID of the category gets submitted to the field called 'category' in the entries database.

    Now, when I print out what has been added to the database I want to have a layout similar to this:

    Code:
    Category name 1
      Entry one
      Entry two
      Entry three
      Entry four
    
    Category name 2
      Entry one
      Entry Two
    And so on...

    I really can't think of a good way to do this so it's nice and dynamic.

    Any ideas please?

    Of course I could do it the bad way and make a query for each of the categories, but that's not really an option as new categories will be added all the time meaning I'd have to edit the php file a lot

    Thanks,
    Craig.

  2. #2
    Gaarrrrr! Dav0s's Avatar
    Join Date
    Aug 2005
    Location
    Bristol
    Posts
    1,442
    Thanks
    1
    Thanked
    3 times in 3 posts
    can you expand on how your database is structured please?

  3. #3
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410
    Table links:
    id, title, url, description, category

    Table categories:
    id, title

    As you can see the links DB and categories DB link up - category in the links table is the same as id in the categories table.

    Craig.

  4. #4
    Senior Member
    Join Date
    Sep 2004
    Posts
    371
    Thanks
    44
    Thanked
    10 times in 9 posts
    I think I understand what you're getting at. Basically you want to have some php that creates your drop down menus based on the categories you have. For example:
    PHP Code:
    $query "SELECT * FROM categories;";
    $result mysql_query($query);

    if (!
    $result) {
       echo 
    "Error";
    } else {
       echo 
    "<select>";
       while (
    $row mysql_fetch_assoc($result)) {
          echo 
    "<option value='".$row['id']."'>".$row['title']."</option>";
       }
       echo 
    "</select>";

    Hope that's what you're looking for

  5. #5
    Senior Member
    Join Date
    Sep 2006
    Location
    UK
    Posts
    1,011
    Thanks
    17
    Thanked
    14 times in 13 posts
    • Craig321's system
      • Motherboard:
      • Asus P8P67 Pro
      • CPU:
      • i7 2600k
      • Memory:
      • 4x 4GB Corsair XMS3 1600MHz
      • Storage:
      • 120GB OCZ Vertex 3
      • Graphics card(s):
      • Asus GTX480 1536MB
      • PSU:
      • 650W Corsair HX
      • Case:
      • Fractal Design Define R3
      • Operating System:
      • Windows 7 Professional 64-bit
      • Monitor(s):
      • Dell U2410
    Thanks very much, but no, it wasn't that I was looking for.

    I've managed to do what I wanted like this:

    PHP Code:
    $sql "SELECT * FROM categories";
    $result mysql_query($sql);

    while(
    $row mysql_fetch_array($result))
    {
      
    $catID $row['id'];
      
    $catTitle $row['title'];

      echo 
    '<b>'.$catTitle.'</b><br />';

      
    $sql2 "SELECT * FROM links WHERE category = '$catID'";
      
    $result2 mysql_query($sql2);

      while(
    $row2 mysql_fetch_array($result2))
      {
        
    $linktitle $row2['title'];
        
    $linkurl $row['url'];

        echo 
    '<a href="'.$linkurl.'">'.$linktitle.'</a><br />';
      }

    Turned out to be pretty simple actually, I just wasn't thinking properly when I asked

    Thanks
    Craig.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP and file uploads timing out too soon
    By McClane in forum Software
    Replies: 12
    Last Post: 02-12-2006, 05:57 PM
  2. e-bay ***5p Listing Day Thursday 7th September***
    By aeonf242 in forum Retail Therapy and Bargains
    Replies: 4
    Last Post: 06-09-2006, 02:41 PM
  3. Online Glossary (php)
    By Dorza in forum Software
    Replies: 7
    Last Post: 16-09-2005, 08:35 PM
  4. Free eBay listing day this Thursday
    By Trash Man in forum Retail Therapy and Bargains
    Replies: 23
    Last Post: 11-01-2004, 11:14 PM
  5. Free e-bay Listing Day - 23/10/03
    By aeonf242 in forum Retail Therapy and Bargains
    Replies: 19
    Last Post: 27-10-2003, 06:55 PM

Posting Permissions

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