while($row = $best_selling_rs->FetchRow()) { $most_sold_sql = 'select count(itemcode) as total_sold, itemcode from shoppingcart where itemcode = "'.$row['itemcode'].'" group by itemcode'; $most_sold_rs = $db->Execute($most_sold_sql); $best_selling .= $most_sold_rs->fields['total_sold'].': '.$most_sold_rs->fields['itemcode'].'
'; } // produces the following infoz... // // How can i find out which itemcode has the largest number? 30: csg 146: famt 42: nfb0301 68: peg199 75: tosl0502 18: wsb0401 220: dd 27: stug0305