php/mysql question

Discussion in 'PHP' started by izlik, Feb 9, 2009.

  1. #1
    Hello

    In one of my databases i have a collumn called "tags" in the table "entrys" i wanted to ask how the SQL question would look like for PHP if i wanted to list all the tags in that collumn when accessing the php file? also, if there was several fields with the same tag it should not display duplicates, only one tag with name X once.

    i hope someone could help me
     
    izlik, Feb 9, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    SELECT DISTINCT `tags` FROM `entrys`.

    Then just query and get the rows.
     
    Danltn, Feb 9, 2009 IP
  3. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #3
    <?php
    //be sure to have db credentials included
    $sql = "select distinct tags from entrys";
    $rs = mysql_query($sql);
    while($row=@mysql_fetch_object($rs)){
    print "$row->tags || ";
    }
    ?>
     
    crivion, Feb 9, 2009 IP
  4. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Thank you. I got one question tough. right now it displays the output like this

    mspaint || wow || Anime,Air Gear || Anime,Dokuro-chan ||

    Is it possible to make it only display the tag "anime" once? and the same thing for all tags. in the output.
     
    izlik, Feb 9, 2009 IP
  5. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #5
    IT needs an explode and add them into array then filter array to show unique vars only but its more to work - have the idea and develop it
     
    crivion, Feb 11, 2009 IP