Make two queries. In the first you would ask fir DISTINCT orderid of all the orders and then in second ask for all the items listed in orderid and then list them in separate table rows.
To be more specific:
echo "<table>";
$sql = "SELECT DISTINCT orderid FROM table";
$result = mysql_query($sql,$database);
while($r=mysql_fetch_assoc($result)){
echo "<tr>";
$sqli = "SELECT * FROM table";
$sqli .= " WHERE orderid = '$r[orderid]'";
$resulti = mysql_query($sqli,$database);
while($ri = mysql_fetch_assoc($resulti)){
echo "<td>".$ri[item]."</td><td>".$ri[qty]."</td>";
}
echo "</tr>";
}
echo "</table>";