在PHP中报告列表功能未显示为查询

I'm having a problem with some specific PHP code that I've been working on for my food ordering system. It's meant to be a reporting code where it uses number of sold items saved in the database and comes up with a simple table showing the top 10 sold items with the respective names in the second column.

But, as far as i've worked with it, it always gives a mixture of sold item such as, 17, 10, 8, 12, 30 item sold.Here's the code I've been working on. Any ideas or amendments i can try? Thanks in advance!

<?php
   include("includes/db.php");
   if(isset($_SESSION["admin"]))
   {
?>                  
 <br><h2 align="center">Top Sellers' Report</h2>
 <table border="0" cellpadding="0" width="500px" align="center" style="border:2px solid black;">
 <tr>
      <td align="center">Sales Information<br></td>
      <td align="center">Item Name<br></td>
  </tr>
  <tr>
      <td colspan="4"><hr size="2" color="black" /></td>          
  </tr>

<?php
    $result=mysql_query("select DISTINCT menurecords.menuname, orderdetails.menuID 
                         from orderdetails 
                         JOIN menurecords ON orderdetails.menuID = menurecords.menuID 
                         ORDER BY orderdetails.quantity DESC") 
                         or die("select * from menurecords"."<br/><br/>".mysql_error());

    while($row=mysql_fetch_array($result)){
?>

  <tr>
      <td align="center">
<?php
    $menuID=$row[1]; 
    $result2=mysql_query("select SUM(quantity) from orderdetails   WHERE orderdetails.menuID='$menuID'");
    while($row2=mysql_fetch_array($result2)){
?>
        Quantity-Sold: <?php echo $row2[0]?><br>    
<?php   
    }
?>

    </td>
    <td align="center">
        <b><?php echo $row[0]?></b></td>
</tr>
<tr>
    <td colspan="4"><hr size="2" /></td>
<?php 
    }
?>
<?php
} else
    echo "No session exists. Please login again to view this page by clicking <a href='adminlogin.php'>here</a>."
?>