Pete, Thanks but I don't understand why you are saying it a poor database design, each record has to have the ORI that has that record entered, how else would you know who has the record entered if the data wasn't there? I tried the COUNT(ORI) routine when I trying to see if could display the number of records and all I was getting was a "1" for each of the 163 different agencies that have records entered.. There is only one extra query that I had to make, not several Ken --- In php-objects@xxxxxxxxxxxxxxx, Pete <cgrp@...> wrote: > > In message <fkrbnb+ug8p@...>, Ken <ken.poyser@...> > writes > >I found the solution!!! > >and it works!!! > > > >I added the following code inside the while statement > > > > > > $sql1 = "SELECT ORI from $table_name where ORI = '$ori'"; > > $result1 =@mysql_query($sql1, $connection) or die > >(mysql_error()); > > $eagycount = @mysql_num_rows($result1); > > I think that you are correct, that there isn't a way to do it properly, > i.e, all in one SQL command, because of the poor database design, > containing all that repeated data. > > But I think that you will find "SELECT COUNT(ORI) FROM $table_name WHERE > ORI = '$ori'" is going to be faster, but with the number of extra > queries that you have had to introduce, there isn't going to be a quick > method. > > -- > Pete Clark > > Sunny Andalucia > http://hotcosta.com/Andalucia.Spain >