Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post

    outputting unique rows only from mysql db

    Here's what I want to do:
    I'm working on a simple image gallery and I need to allow users to sort images into galleries they create. I'm using a dropdown to allow them to choose from galleries they have already created.

    Here's what I'm using:
    PHP Code:
    $result=mysql_query("SELECT DISTINCT * FROM media WHERE username='$username'");

    while(
    $row mysql_fetch_array($result)){
    //show existing galleries
      
    echo "<option>";
      echo 
    $row['gallery'];
      echo 
    "</option>";
      } 
    Here's my problem (if you gurus haven't discovered already):
    Even with the DISTINCT clause in the select statement, I still have it outputting EVERY images gallery name into the drop down. (Sorry if that's not real clear. If you don't understand, I'll be glad to attempt to explain it in another way)

    Thanks in advance for any help!
    <3 CF

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    edit: never mind, Mis-read the question and answered it totally wrong

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by Meltdown View Post
    I'll be glad to attempt to explain it in another way
    Yes, do that. Explain your table structure too, and why you aren't using the a user id/relational setup instead of the username.

  • #4
    Regular Coder
    Join Date
    Apr 2003
    Location
    Matewan, WV
    Posts
    201
    Thanks
    0
    Thanked 1 Time in 1 Post
    table structure:
    Columns:
    username
    dateadded
    description
    imagename
    id (for image)
    gallery

    Restating my problem:
    there will be multiple images linked to the same username in this table. ALL users will have their image information stored in the same table (above structure). Every user will have the ability to sort their images into different galleries (categories). They will be able to name these categories themselves. Now, for my problem. When they want to insert a new image into an existing category, I want them to be able to select the existing category from the gallery column via a drop down menu (so: I need to pull the data from the column "gallery" and display it in a drop down menu while eliminating multiple occurrences of the same gallery name. So I need to know how to list the results of the column "gallery" in a drop down menu while eliminating multiple occurrences of the same word (gallery name) in the drop down. There are multiple occurrences of the same word (gallery name) because there are multiple images tagged with the same gallery name.
    The portion in bold says it all.

    I appreciate your time, guys...
    Last edited by Meltdown; 11-22-2007 at 02:50 AM. Reason: clarification
    <3 CF

  • #5
    New Coder
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    Using the UNIQUE keyword in your SQL query should do that for you. The idea is that it returns only a single occurrence of a given value no matter how many times that value may appear in the table.
    Of all the things I've lost in my life time, my mind is the one I miss the most!

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Have a table for the images(with fields for user id, and gallery id), a table for galleries(with a user id field), and a table for users(use your current one I guess). Then you can simply select the galleries for that user from the gallery table, etc.


  •  

    Posting Permissions

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