SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: DISTINCT output

  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DISTINCT output

    I have the following Query and PHP:
    Code:
        $menulisting = $pdo->query("SELECT DISTINCT MK.menu_kaart_id, MK.menu_kaart_type_nl, MK.menu_kaart_type_en, MI.language_abbr, MI.menu_item, MI.menu_item_description, MI.menu_item_price, MI.menu_item_price_2 
    	                        FROM menu_kaart MK
                                    INNER JOIN menu_kaart_items MI ON MK.menu_kaart_id = MI.menu_kaart_id
                                    WHERE MK.menu_kaart_id = $menu_id
                                    AND   MI.language_abbr = '$language_abbr' "); 
    	
        $menulisting->setFetchMode(PDO::FETCH_ASSOC);
    	  
        while($row = $menulisting->fetch()) {
    	  $menu_title = $row["menu_kaart_type_$language_abbr"];
          echo '<h1>'. $menu_title .'</h1>';
    	}
    But the menu_title is echod multiply the number of menu_items each menu_kaart_id has. As you can see am I using DISTINCT and have I tried RIGHT JOIN instead of INNER JOIN, but nothing is doing the trick. What should I change in this structure. Thank you in advance
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Solved. I just used two separate queries instead.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,276
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    solved worked around FTFY

    printing out a one-to-many relationship so that the "one" data appears only once is a pretty basic programming technique

    unfortunately i don't do php or i'd show you
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're right about the worked around I am not the best in PHP myself. Used to work most of the time with CF but hey
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


Bookmarks

Posting Permissions

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