title: Not getting required result after joining 2 tables
body: <p>I have a view where i need to get list of all dishes from menu table according to main_menuid for a particular user, But here i need to put some conditions
  Currently i am using 3 tables for the entire process (table view for all 3 is given at the end)</p>
  
  <pre><code>1) main_menu
  2) menu
  3) cart
  </code></pre>
  
  <p>1) I need to get list of dishes according to main_menuid</p>
  
  <p>so here if i need a list of dishes below MM1, so list of dishes that i should get from menu table is <code>(main_menuid is the id of main_menu table)</code></p>
  
  <pre><code>id  main_menuid  dish    
  1        1        D1
  2        1        D2
  3        1        D3
  </code></pre>
  
  <p>code i used to get the above data is</p>
  
  <pre><code>$sql = "select * from menu where main_menuid = '".$mainmenuid."'";
  $result = mysqli_query($con, $sql);
  if (mysqli_num_rows($result) &gt; 0) 
      {
          while($row = mysqli_fetch_assoc($result))
              {
                  print_r($row);
              }                   
      }
  </code></pre>
  
  <p>2) i will also have a userid with me so now i need to display the above list to a particular user <code>(Let the userid be "1")</code>, but if he already has added any of the above product to cart earlier then it's quanity should also get fetched from cart and for rest of the items(that are not added by him to the cart but is present in the above list) the quantity will be null, so the resulting view should be like this  <code>(menuid is the id of menu table)</code></p>
  
  <pre><code>id  main_menuid  menuid  dish    quantity  userid
  1        1         1      D1       3        1
  2        1         1      D2       2        1
  3        1         1      D3       0        1
  </code></pre>
  
  <p>code that i tried for the above result is (but it didn't gave me the desired result)</p>
  
  <pre><code>SELECT  menu.main_menuid, menu.dish, cart.userid, 
      cart.quantity 
  FROM menu 
  LEFT JOIN cart ON menu.id=cart.menuid  
  WHERE main_menuid = '".$main_menuid."' and userid = '".$userid."'
  </code></pre>
  
  <p>Below is a sample view of all the tables that are being used in the above process</p>
  
  <p>main menu</p>
  
  <pre><code>id   mainmenu_name
  1     MM1
  2     MM2
  3     MM3
  4     MM4
  </code></pre>
  
  <p>menu</p>
  
  <pre><code>id  main_menuid  dish    
  1        1        D1
  2        1        D2
  3        1        D3
  4        2        D4
  5        3        D5
  6        4        D6
  </code></pre>
  
  <p>cart</p>
  
  <pre><code>id  userid  menuid  dish  main_menuid  quantity
  1     1       1      D1      1            3
  2     1       2      D2      1            2 
  3     2       1      D1      1            3
  </code></pre>
  
  <p>can anyone please tell how to achieve the desired result (DBMS: mysql)</p>