Only get record once if duplicate?!?

Discussion in 'PHP' started by jmansa, Jun 13, 2009.

  1. #1
    How can I get records out in an array, but only once even if there is an duplicate...

    I want to get a all the courses a golfer has played during a season, but the player might have played the same course several of times, and I only wants to show once which courses he has played.

    $sql="SELECT * FROM ".$prefix."_played WHERE user='$userid' AND season=1";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result)){
    	
    	$course = $row['courseid'];
    	
    }
    PHP:
    This just loops out each record even if the courseid is the same...

    Please help...
     
    jmansa, Jun 13, 2009 IP
  2. findonline

    findonline Peon

    Messages:
    149
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could try "select distinct ...." rather than "select ..." in your statement, the distinct keyword makes it so duplicate records are not returned, but I believe that all field results need to be the same in order for it to count as a duplicate....
     
    findonline, Jun 13, 2009 IP
  3. jmansa

    jmansa Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, that was what I was looking for, but... I want it to be with an INNER JOIN like this:
    $sql="SELECT DISTINCT courseid FROM ".$prefix."_stroke 
    			INNER JOIN ".$prefix."_courses ON ".$prefix."_stroke.courseid = ".$prefix."_courses.courseid
    			WHERE user='$userid'";
    PHP:
    When I set it up like above I get error, but if I change "SELECT DISTINCT courseid" to "SELECT *" I get no errors but alot of duplicate outputs... How do I use this with "INNER JOIN"?

    Thanks.
     
    jmansa, Jun 13, 2009 IP