Pulling out matching values from a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Pulling out matching values from a database

    Hi, I'm using a mysql database to store information for the frontpage of my website, http://claninfectionist.com, I'm adding the tutorials right now, everything thing is going fine, but there is a problem that I forsaw, and lo and behold it happened. I'm one table called tutorials and storing the tutorials with one value being type, (example: photoshop, gimp, apophysis.) I want to use the type column to make a category page, the code I am using is this:

    [PHP]$sql = mysql_query('SE LECT `type` FROM `tutorials`') or die("Error: ".mysql_error() );

    while($info = mysql_fetch_arr ay($sql)) {
    echo ucfirst($info['type'])."<br />";
    }[/PHP]

    Since I have more than one of each type of tutorial (actually, right now, I have two of each) its printing out the type for each one, so I'm getting two photoshops, two gimps, and two apophysis'. Is there some code that I can use to only pull out each type once, even if it is in the type field more than once. My first thought was some comparison code, but I've not been doing PHP for long, so I don't really know how. Can anyone give me an easy way (or just any way, if there is no easy way, I'm not too picky) to do this please, I would be very grateful.

    The reason that I have the type in there like this, instead of having each type in its own seperate table, is becuase I want to have someone be able to go to http://claninfectionist.com/tutorials/ and it'll show all the different programs we have tutorials for, then if they go to http://claninfectionist.com/tutorials/?cat=photoshop, it'll show all the tutorials for photoshop, then they can go to http://claninfectionist.com/tutorial...tut=GrungeText and it'll show that tutorial. I know this is possible, and relatively simple, so can anyone help me?

    ~HaLo2FrEeEk
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Use the GROUP BY attribute as in:
    Code:
    SELECT type FROM tables GROUP BY type;
    Ronald :cool:

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      You are amazing, thank you.

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        Sorry for the double post, but I have a further question.

        I want to sort these further by category (I will change the current "type" to "program" and type will become the...type of tutorial, whether that be graphics, video, php, etc...

        If I add an extra column to the table, called type (after changing current type to program), how will I sort them so that I can get an output like this:

        Graphics:
        Apophysis
        Gimp
        Photoshop

        Video:
        Vegas 7

        Is this possible?

        Thank you in advance.

        Comment

        • HaLo2FrEeEk
          Contributor
          • Feb 2007
          • 404

          #5
          Bump...anyone, please I need some help.

          Comment

          • HaLo2FrEeEk
            Contributor
            • Feb 2007
            • 404

            #6
            Please!

            I need some help folks, I tried to do this on my own but I can't find anything that works.

            Comment

            Working...