Hi xpi0t0s, I tried what you said. Took a while to work things out but you can see the query string and the function below I created. I am running on a Windows 2003 server with MySQL 5.1.34. So had to change it a little to make it work and not break.. LOL...But it still does not order the results with the record with all 7 balls at the top and then and record with only 6 balls below and so on... I can see how the code works and it really makes sence! It checks all the balls in the coloums and if found increment total. If total = 7 then top. So total will be between 7 to 0 and Order By sorts it all.. Strange why it not work.. The numbers 43,25,16,48,49,34,36 has got a record with these numbers. Maybe your trained eye will spot something. For now I'll keep at it and let you know if I get it..


QueryString="select * from lottosites ORDER BY ballmatch(43,25,16,48,49,34,36) DESC"

------------------------------------

CREATE DEFINER=`user`@`localhost` FUNCTION `ballmatch`(pBall1 INT, pBall2 INT, pBall3 INT, pBall4 INT, pBall5 INT, pBall6 INT, pBonusBall INT) RETURNS int(11)
BEGIN
DECLARE total int(11);
SET total=0;
if @Ball1 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @Ball2 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @Ball3 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @Ball4 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @Ball5 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @Ball6 in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
if @BonusBall in (pBall1, pBall2, pBall3, pBall4, pBall5, pBall6, pBonusBall) then SET total=total + 1; end if;
RETURN total;
END